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

How to get Enter key to submit form?

Status
Not open for further replies.

donishere

Programmer
May 7, 2002
101
How do I set up a web page so that when I press Enter, it will submit a form? The form right now is using an image as the submit button instead of a usual text button.

thanks,
don
 
if you only have one form on the page the default behaviour of the enter button is to submit the form:

<html>
<head>
</head>
<body>
<form action=&quot;somepage.asp&quot; method=get>
<input type=text name=&quot;text1&quot;><br>
<input type=text name=&quot;text2&quot;><br>
<input type=image src=&quot;logo.gif&quot;>
</form>
</body>
</html>


the following example shows that when you press the enter key in either text field it will submit the form even with an image submit

If there is more than 1 form, depending on which form element has focus, that corresponding form will be submitted
when the enter key is pressed. (IE5)
 
Here's a more detailed description of the issue:

I have 1 form on a web page. The form has two buttons. One is a plain textual button. The other button is an image. The textual button is assigned a JavaScript function and will is not supposed to submit the form. The image button is the button that should be submitting the form. However, when I press Enter in the form, the browser will treat it as clicking on the textual button (performing the JavaScript). How do I set up the form so that pressing Enter tells the browser to click on the image button and thus, submitting the form?

thanks,
don
 
would it be possible to see the relevant code because when i add a text button to the code above it still submits the form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top