Onblur prevents onsubmit on form submission

I have validation functions that are called on the onblur

appropriate input field. at the same time I call the same validation functions with one function validateall()

and get validateall()

called on onsubmit

. now the problem is that some error happened and I corrected it and submitted the form at this time when it is called onblur

which prevents the event from being triggered onsubmit

. this is the problem i only faced in Firefox.

JavaScript:

function validateFormOnSubmit(theForm) 
{
vUsername(theForm.userName,document.getElementById('UError'));//this will return true or false depends on error occurrence. 
}

      

HTML:

<form name="form" onsubmit="return validateFormOnSubmit(this);">
<input type="text" id="userName" onblur="vUsername(this,UError);">

      

// UError is the div id where I will print error messages.

+3


source to share


2 answers


Use delay () function or setTimeOut () function for onBlur.



this link will help you too. jQuery onblur check

+1


source


Add a setTimeout function to your onBlur event. To pass your parameters, you must use an anonymous function:

<input type="text" id="userName" onblur="setTimeout(function(){ vUsername(this,UError) }, 200);">

      



Your event message should now be faster than onBlur :-)

0


source







All Articles