Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8174085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:21:43+00:00 2026-06-06T22:21:43+00:00

I’m using struts1.3.8. I’m using struts ValidatorPlugIn for generating client side and server side

  • 0

I’m using struts1.3.8. I’m using struts ValidatorPlugIn for generating client side and server side validation messages.
Now client side javascript is generated by validator plugin. If there is any validation errors it is displaying in alert messages. But i want to display them besides the text field.
I’m still now working with alert messages only.. But now requirement changed. I tried but no use…
How to do it?
This is the code generated by plugin

   `enter code here` function jcv_handleErrors(messages, focusField) {
          if (focusField && focusField != null) {
              var doFocus = true;
              if (focusField.disabled || focusField.type == 'hidden') {
                  doFocus = false;
              }
              if (doFocus && 
                  focusField.style && 
                  focusField.style.visibility &&
                  focusField.style.visibility == 'hidden') {
                  doFocus = false;
              }
              if (doFocus) {
                  focusField.focus();
              }
          }
          alert(messages.join('\n'));
      }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:21:44+00:00Added an answer on June 6, 2026 at 10:21 pm

    Without specific information, all I can really suggest is a variation of the following:

    window.alert = function(message){
        console.log(message);
    }
    

    JS Fiddle demo.

    Which simply ensures that any messages passed to alert() get passed, instead, to the console.log().

    You could, instead, target the messages to a particular element:

    window.alert = function(message) {
        var output = document.getElementById('output'),
            newTextContainer = document.createElement('p'),
            text = document.createTextNode(message);
        newTextContainer.appendChild(text);
        output.appendChild(newTextContainer);
    }
    

    JS Fiddle demo.

    Using either of these will break any usage of your alert() function in your page, though. So I’d suggest, instead, creating a new function with the latter example (immediately above) and calling that function, rather than over-writing alert().

    With regards to creating a custom function to handle your alerts, as well as specify a particular element to which the new ‘alerts’ should be appended:

    function newAlert(message, elem) {
        // message is a string containing the message to display.
        // elem is the id of the element into which the message should be displayed,
        // defaults to an id of 'output' if no element is specified.
        var output = elem ? document.getElementById(elem) : document.getElementById('output'),
            newTextContainer = document.createElement('p'),
            text = document.createTextNode(message);
        newTextContainer.appendChild(text);
        output.appendChild(newTextContainer);
    }
    

    JS Fiddle demo.


    Edited in response to question from OP, below:

    Next again submit the form I want to overwrite the previous error message. Not twice display the same message.

    There are a couple of ways of doing this, assuming you only want to show the last of the error messages, rather than appending those error messages; in the first example I’m using a while loop to remove the firstChild of the output element and, when empty, appending the new error message:

    function newAlert(message, elem) {
        var output = elem ? document.getElementById(elem) : document.getElementById('output'),
            newTextContainer = document.createElement('p'),
            text = document.createTextNode(message);
        while (output.firstChild){
            output.removeChild(output.firstChild);
        }
        newTextContainer.appendChild(text);
        output.appendChild(newTextContainer);
    }
    

    JS Fiddle demo.

    An alternative is to get a reference to the first paragraph element in the output element (if one exists, otherwise create one) and then simply overwrite the text in that element:

    function newAlert(message, elem) {
        var output = elem ? document.getElementById(elem) : document.getElementById('output'),
            textContainer = output.getElementsByTagName('p')[0] || output.appendChild(document.createElement('p'));
    
        if (textContainer.firstChild){
            textContainer
                .firstChild
                .nodeValue == message;
        }
        else {
            textContainer
                .appendChild(document
                             .createTextNode(message));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.