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 Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hitting the enter key submits form

Status
Not open for further replies.

Katriona

Programmer
Aug 29, 1999
24
AU
How can I stop the enter key submitting a form?
 
Dear Katriona,<br><br>The simplest way to accomplish that is to not have an input element of type 'submit' in the form. Obviously you need another mechanism to submit the form like an input type of 'button' with an onclick() handler.<br><br>&quot;But, that's just my opinion... I could be wrong&quot;.<br>-pete
 
To illustrate what Pete said:<br><br>&lt;html&gt;&lt;head&gt;<br>&lt;script language='javascript'&gt;<br>function submitme(){<br>document.forms[0].submit();<br>return true;<br>}<br>&lt;/script&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>&lt;form action=&quot;mypage.asp&quot; method=&quot;post&quot;&gt;<br>&lt;input type=&quot;button&quot; value=&quot;Submit&quot; onclick=&quot;return submitme()&quot;&gt;<br><br>NOTE: the 'return' in the onclick handler is important.<br>&lt;/form&gt;&lt;/body&gt;&lt;/html&gt; <p>nick bulka<br><a href=mailto: > </a><br><a href= > </a><br>
 
Thanks for all the help. Most useful.<br><br>Keep smiling :)<br><br>Katriona
 
Hi NickBulka,

Why is 'return' in the onclick handler important?

What does it do?

Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top