handling onblur

H

hrpreet

Hi All,

I have few textfields and dropdowns in my jsp, form is submitted on
clicking an image link.
In case there is an error for instance some text field is left empty,
then message is displayed below respective fields ( using spans, inner
html). The message is displayed onblur event of the field. So if there
was an error then message is displayed, now if the user corrects the
error and clicks the link then first the message disaapears ,which is
desired ,but he has to click again to submit the form. please suggest a
way to handle this. So that user doesn't have to click the link twice
to submit the form.I tried having onmousedown and onfocus events on
image , but then sometimes the form was submitted twice which gave
backend errors.

Thanks
 
W

web.dev

hrpreet said:
Hi All,

I have few textfields and dropdowns in my jsp, form is submitted on
clicking an image link.
In case there is an error for instance some text field is left empty,
then message is displayed below respective fields ( using spans, inner
html). The message is displayed onblur event of the field. So if there
was an error then message is displayed, now if the user corrects the
error and clicks the link then first the message disaapears ,which is
desired ,but he has to click again to submit the form. please suggest a
way to handle this. So that user doesn't have to click the link twice
to submit the form.I tried having onmousedown and onfocus events on
image , but then sometimes the form was submitted twice which gave
backend errors.

Thanks

A form element has an onsubmit event handler. Consider using that to
validate your form instead of using onblur. For example:

html:

<form action = "action.jsp" method = "post" onsubmit = "return
validate(this)">
....[elements]...
</form>

javascript:

function validate(myForm)
{
//perform your validation routine here
if(...)
{
//display your error message
//return false will cause the form NOT to submit
return false;
}

//return true will cause the form to submit
return true;
}

It would be also nice to take into consideration if the user has
disabled javascript. Therefore you should also do validation on the
server side.
 
H

hrpreet

Thanks a lot for your reply.
But it was client's requirement to hav it onblur. i kept trying
different options, and capturing onmouse down event on image has helped
me.

You are right about server side validations.

Thanks again
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top