Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IE - Enter Key to submit a form

Status
Not open for further replies.

elamacch

Programmer
May 1, 2002
1
US
I am working with submit buttons and forms. A number of the <input>'s on my page have onblur events defined. In IE when the enter key is used to submit the form the submit event is getting fired before the onblur event. The onblur is doing data validations that should prevent the user from getting invalid data in the database. So when I have focus on the input, enter invalid data, and hit enter to submit the form the validation is done after the submit is started so I get an error message displayed, click ok, and the form is submitted.

I've tried a few things to get around this and the only thing that seems to work nicely in IE 5.5/6.0 and Netscape 6.1/6.2 is removing the onblur events and putting the validations in the onSubmit function.

Any ideas would be greatly appreciated.

Thanks,
 
You should put any validation in the form's onSubmit event rather than a form element'e onBlur.

so, for example:

<form name=&quot;frmForm&quot; action=&quot;nextpage&quot; method=&quot;Post&quot; onSubmit=&quot;return ValidateForm();&quot;>

Then in your javascript validation:

<script language=&quot;javascript>
Function Validate Form() {

//Your validation here

return false; //to not submit form

return true; //to submit form



}
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top