File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes submitting form when 'enter' is hit Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "submitting form when Watch "submitting form when New topic

submitting form when 'enter' is hit

Anthony Leroy

Joined: Aug 02, 2001
Posts: 20
How do I stop the form from submitting when enter is hit?
OR how do I call a javascript function when enter is hit in a form field?
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
To call a javascript function use this in your form tag:
<form name='myForm' onsubmit='return jsFunction();'>
Then have your function return true or false if its ok or not ok to submit it. If you return false the form isn't submitted and you can display an alert box or something else to the user to fix whatever's wrong and try again.
hope that helps

Sun Certified Programmer for the Java� 2 Platform

I agree. Here's the link:
subject: submitting form when 'enter' is hit
It's not a secret anymore!