开发者

jquery toggle blur on all textboxes?

开发者 https://www.devze.com 2022-12-13 08:42 出处:网络
I have a form which is validated through jquery, but I need the blur event to fire again once the submit button is checked, in case the user deletes anything. It shows an error but the \"tick\" is sti

I have a form which is validated through jquery, but I need the blur event to fire again once the submit button is checked, in case the user deletes anything. It shows an error but the "tick" is still displayed next to the text box, as this only changes on the blur event.

How can I toggle the blur event to all text boxes to re-validate them?

Thanks

edit: added code

 if(httpxml.readyState==4)

 { 
  if (httpxml.responseText.indexOf("Successful") >= 0)
 {  
  $("#result").show("slow");
  $("#result").html("Project request has successfully been sent");
  $("#result").removeClass("result_error");
}
else if (httpxml.responseText.indexOf("Fail") >= 0)
{
 $("#result").html("One or more errors have occured, please fix and submit again");
 $("#result").addClass("result_error");
 $("#result").show("slow");
 $(':text').trigger('blur'); <<--- Blur text boxes here 
}   

}

checking:

   function check_email(email)
{
    var httpRequest;
         make_request()


    $("#loading").show(); 

    function stateck() 
    {
        if(httpxml.readyState==4)
        {
            if (httpxml.responseText.indexOf ("Email Ok") >= 0)
        {

            $("#email_tick").show();
            $("#email_cross").hide();
            $("#email_error").hide("normal");   
            $("#loading").hide();
            emailok = true;


        }

         else 
        {               
            $("#email_tick").hide();
            $("#email_cross").show();
            document.getElementById('email开发者_如何学编程_error').innerhtml = "Invalid email";
            $("#email_error").show("slow");
            $("#loading").hide();
            emailok = false;

        }
        checkCanSubmit();           
        }
    }

httpxml.onreadystatechange=stateck;
email_url="../checking/check_email.php?email=" + email.value;
httpxml.open("GET",email_url,true);
httpxml.send(null);
}


Im not really clear on what youre asking but if you are asking how to trigger the blur manually:

$(':text').trigger('blur');


You can trigger it by:

$('input:text').blur();
// or
$('input:text').trigger('blur');


$('#button').click(function () {
    $('input').blur();
});

The code reads as:

When the button with id="button" is clicked, find all <input /> and fire the blur event on them.

Tune the selectors to match your needs.

0

精彩评论

暂无评论...
验证码 换一张
取 消