Solved

form submission on 'enter'

Posted on 1998-08-16
15
184 Views
Last Modified: 2010-04-09
Heya..

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.
0
Comment
Question by:Q010797
  • 6
  • 4
  • 2
  • +3
15 Comments
 
LVL 12

Expert Comment

by:Otta
ID: 1836723
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
0
 
LVL 1

Author Comment

by:Q010797
ID: 1836724
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>
<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>
</tr>
</form>
0
 
LVL 12

Expert Comment

by:Otta
ID: 1836725
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>
</FORM>
</BODY></HTML>
0
 

Expert Comment

by:th_c_man
ID: 1836726
Doesn't pressing enter work anyway?

It always does for me.

i use NN4, NN3, or MSIE3
0
 
LVL 1

Author Comment

by:Q010797
ID: 1836727
so you're telling me it's impossible?  won't work?
0
 
LVL 2

Accepted Solution

by:
SirCaleb earned 50 total points
ID: 1836728
You need to use the onchange command..
Put this in your <head>:

<script language="Javascript">
<!--
function sendit() {
document.formname.submit(document.formname);
return true;
}
//-->
</script>

Put this in your body:

<FORM NAME="FORMNAME" METHOD="POST" ACTION="/YOUR/PATH.PL">
<INPUT TYPE="TEXT" SIZE=25 VALUE="" onchange="sendit()">
</FORM>

You may have to "tweak" this a little but it should work....
0
 
LVL 12

Expert Comment

by:Otta
ID: 1836729
This code works:
This code works:

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

Try it!
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:SirCaleb
ID: 1836730
otta, that will not work in Netscape 3.0
0
 
LVL 12

Expert Comment

by:Otta
ID: 1836731
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".
0
 
LVL 2

Expert Comment

by:SirCaleb
ID: 1836732
the answer that I posted works in ALL browsers...I know...I tested it!
0
 
LVL 12

Expert Comment

by:Otta
ID: 1836733
SirCaleb,
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.
0
 
LVL 2

Expert Comment

by:SirCaleb
ID: 1836734
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....
0
 
LVL 4

Expert Comment

by:rafistern
ID: 1836735
I think your problem is that you are using <input type=button>. Use <input type=submit> and it will work.
0
 
LVL 3

Expert Comment

by:NullTerminator
ID: 1836736
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.
0
 
LVL 12

Expert Comment

by:Otta
ID: 1836737
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.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SVG Logo 4 32
Glyph icons in Bootstrap 3 4 37
Need to click button twice to get results 2 32
File download script VBSCRIPT fail on download PPT files 2 33
Showing your events from Google Calendar in Google Maps Why? I travel all week and I thought it would be ideal if staff in office knew where I was based on my calendar. (OK real reason: my son wanted to see where I would be working, and I thoug…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now