We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


form submission on 'enter'

Q010797 asked
Medium Priority
Last Modified: 2010-04-09

I want the "Enter" key to submit the form.  Instead of clicking on the submit button, i want enter to do this.

must work with both IE and netscape.
Watch Question

Using "Enter" inside a <TEXTAREA> element
forces a "new-line", rather than doing a "submit".
So, do not use <TEXTAREA> in your <FORM>.
Otherwise, "Enter" works fine to "submit".
Example: http://www.altavista.digital.com


There are no <textarea> tags in the html.
This is the form I want to get working.  Have others too which I am hopeing the same code will fix.

<form name="usage">
<tr><td>Username:</td><td><input type="text" name="username" size="9" maxlength="8"></td></tr>
<tr><td>Password:</td><td><input type="password" name="password" size="9" maxlength="8"></td></tr>
<td><center><input type="button" value="Display time used" onClick="displayLocation();"></center></td>
<td><center><input type="reset" value="Clear Information"></center></td>
<tr><td colspan="2"><br><br><br><br><br></td></tr>

The 'altavista' page works fine,
but the "trick" is that there is only one (not two)
<INPUT TYPE="text"> fields,
and there is only one <INPUT TYPE="submit"> fields.

This code works:

<html><head><title>Extracted from AltaVista</title></head><body>
<FORM name=mfrm method=GET action="/cgi-bin/query">
<INPUT NAME=Q size=50 maxlength=80 VALUE="default">
<INPUT TYPE="submit" VALUE="Submit"><br>

Doesn't pressing enter work anyway?

It always does for me.

i use NN4, NN3, or MSIE3


so you're telling me it's impossible?  won't work?
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

This code works:
This code works:

    <title>Extracted from AltaVista</title>
  <FORM name=myform method=GET action="/cgi-bin/query">
    <INPUT NAME=Q size=50 maxlength=80 VALUE="default">
    <INPUT TYPE="submit" VALUE="Submit">

Try it!

otta, that will not work in Netscape 3.0

SirCaleb wrote:
> that will not work in Netscape 3.0

It works correctly, in Netscape 2.02 for OS/2.

Maybe, the "correct" answer to Q's question
is "it cannot be done".

the answer that I posted works in ALL browsers...I know...I tested it!

I tried your code in several web-browsers, and it didn't work.  
You overstate your claim when you say 'ALL'.
The "top 90%" maybe, but not "all",
since not "all" browsers support JavaScript.

why would anyone be using a browser without javascript?
That code works in Netscape 3.x and 4.x, Microsoft IE 3.x and 4.x
Those who are using a lower version browser than 3.x just need to get with the times....
I think your problem is that you are using <input type=button>. Use <input type=submit> and it will work.
The problem you are all missing is that it will work with a form with one edit control.  With more than one edit control it will not, its that simple.  With HTML 4 and the event bubbling model, you might be able to grab the enter key but I haven't fiddled with it because I need backward compatablitiy with Netscape.

NullTerminator wrote:
> The problem you are  all  missing .., one edit control ...

I alluded to that point in my previous message:

> The 'altavista' page works fine,
> but the "trick" is that there is only one (not two)
>     <INPUT TYPE="text"> fields,
> and there is only one <INPUT TYPE="submit"> field.

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.