tags:

views:

153

answers:

3

Hi, 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);
}
A: 
$('#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.

Emil Ivanov
Thanks this doesnt seem to work, I am using $('input').blur(); but its not actually on the button click, it checks if a response text is fail. I have a div showing the error this works fine, blur just doesnt work.
Elliott
+1  A: 

You can trigger it by:

$('input:text').blur();
// or
$('input:text').trigger('blur');
CMS
+1  A: 

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

$(':text').trigger('blur');
prodigitalson
Thanks still cannot get it working
Elliott
can you post the relevant parts of your JS and html? I think we may all be misunderstanding what it is you need to do. It will be easier to figure out if we can see what we are dealing with :-)
prodigitalson
added =).........
Elliott
i saw that :-) seem my on your initial question above.
prodigitalson