Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

submitting form when 'enter' is hit

 
Anthony Leroy
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anthony
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

------------------
Dave
Sun Certified Programmer for the Java� 2 Platform
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic