user2046302
user2046302

Reputation: 41

Onblur prevents onsubmit while submitting form

i have validation functions which is being called on onblur of respective input field. at the same time i am calling same validation functions with one say validateall() function and validateall() is being called on onsubmit. now the problem is if some error has occured and i have corrected it and submit the form at that time onblur is being called which is preventing from calling onsubmit event. this problem i am facing in Firefox only.

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 div id where i'll be printing error msgs.

Upvotes: 4

Views: 2473

Answers (2)

alexP
alexP

Reputation: 3765

Add a setTimeout-function to your onBlur-event. To hand over your parameters you have to use a anonymous function:

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

Now your submit-event should be faster than onBlur :-)

Upvotes: 0

sasi
sasi

Reputation: 4318

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

this link also helps you.. jQuery validation onblur

Upvotes: 1

Related Questions