tags:

views:

73

answers:

1

Ok I have 2 error messages being return which in turn displays 2 messages of the same thing. how can I only show one message?

jQuery.noConflict();

   jQuery(document).ready(function(){
      if (jQuery("span.errorMessage").length > 0) {                                                              
         var $this = jQuery("span.errorMessage");
         var t = $this.text();

         // Clear the text
         $this.text('');

         // Add new message
         $this.text('No search criteria was specified.');

         // Change the layout
         jQuery('#errorMessage').appendTo(jQuery('#message_display'));
      }
   });

Adding the HTML for the error's

<span id="errorMessage">    
         <ul>
     <li><span class="errorMessage">No search criteria was specified.</span></li>
     <li><span class="errorMessage">No search criteria was specified.</span></li>
    </ul>
</span>
+2  A: 

It appears that you are appending the text to #errormessage, but clearing out #this.text(). I'm guessing that you are needing to clear the #errormessage before adding new errors to it.

Try This....

<div id="errorMessage">    
    <ul>
        <li><span class="errorMessage">1 No search criteria was specified.</span></li>
        <li><span class="errorMessage">2 No search criteria was specified.</span></li>
        <li><span class="errorMessage">3 No search criteria was specified.</span></li>
        <li><span class="errorMessage">4 No search criteria was specified.</span></li>
    </ul>
</div>

$(document).ready(function() {
    SetupMessageManager();
    $('.errorMessage').parent().hide();
    $('.errorMessage:first').parent().show();
});
RSolberg
Yes it's passing LOG info but I just need a generic error message
Phill Pafford
Also the error messages are passed back on a UL, each message is a LI
Phill Pafford
oh ok... so you have a list of errors (#message_display) and there is a duplicate message within the list?
RSolberg
added error HTML
Phill Pafford
does the validation duplicate the message on the first pass, or does it only do it on the second, and each one there after? So after 3 button clicks, you have 3 messages?
RSolberg
the script is passing 2 error messages back one one submit call, but I only need one message to display
Phill Pafford
if there are more than 1 message it always comes as a LI in the UL, but regardless of the amount I only need one to display
Phill Pafford
If you only want 1 message at any time, you should clear the UL of messages before adding a new one.
RSolberg
how do I do this?
Phill Pafford
just changed the code to hide all of the LI items and then display the first...
RSolberg
Thanks worked like a charm :)
Phill Pafford