only perform the post if the error message div isnt there, or has no
text in it


if( !($('#divSteps3')==undefined) && $('div.error-message').text
().length>0) )

something like that

On Aug 31, 1:53 pm, "Dave Maharaj :: WidePixels.com"
<d...@widepixels.com> wrote:
> I have this script
>
> $(document).ready( function() {
>
>     $('#username').blur( function () {
>
>         fieldName = $(this).attr('id');
>         fieldValue = $(this).val();
>
>         $.post('/users/ajax_validate', {
>                                         field: fieldName,
>                                         value: fieldValue
>                                         },
>                function(error) {
>
>                    if(error.length != 0) {                
>
>                        $('#username').after('<div class="error-message"
> id="'+ fieldName +'-exists">' + error + '</div>');
>                    }
>                    else {
>                        $('#' + fieldName + '-exists').remove();
>                    }
>                });
>      });  
>
> });
>
> Which sends a requet to determine if the username is taken...pretty simple
> if so it displays Please choose another message. My problem is if the user
> goes back to the field and then leaves without changing it it sends the
> request again and then shows
> "Please choose another name"
> "Please choose another name"
>
> How can I modify the script so if there is an error and not fixed to leave
> the message and not repeat it?
>
> Dave

Reply via email to