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

How to submit form with enter key..

Status
Not open for further replies.

Frank123

MIS
Sep 17, 2001
77
US
Hi everyone, I can't figure out how to submit my form when a user hits the enter key. Right now I have it that when the user hits the enter key the form is submitted, but it would be much nicer if they could just hit the enter key to submit.

Thanks!!
 
Hi Frank,

Sorry - can you read your own question again and re-post?

Regards,

Darrylle "Never argue with an idiot, he'll bring you down to his level - then beat you with experience."
 
I hope this was a very large typo or I've been up too long
Frank123
onClick
onSubmit
etc
etc I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
Sorry about that, it was a typo. What I wanted to say is the following:

Right now the user has to either tab down or click the "submit" button I created. I'd like to make this process easier by having the enter key act like the "submit" button.

Any ideas? Thanks!



 
I would use javascript onKeyPress. here's a example
<SCRIPT TYPE=&quot;text/javascript&quot;>
<!--
function submitenter(myfield,e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
{
myfield.form.submit();
return false;
}
else
return true;
}
//-->
</SCRIPT>

<body>
<FORM ACTION=&quot;blah.asp&quot;>
name: <INPUT NAME=realname SIZE=15><BR>
password: <INPUT NAME=password TYPE=PASSWORD SIZE=10
onKeyPress=&quot;return submitenter(this,event)&quot;><BR>
<INPUT TYPE=SUBMIT VALUE=&quot;Log In&quot;>
</FORM>


this is from I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
 
Is there a variation for VBS - esp. where a cmd button already has an event action assigned? Two questions in one here, I guess. 1) how to make a cmd button event fire by the enter key, 2) is it possible to include two event actions in the <input type=&quot;button&quot; ...> definition? TY!
 
PS- my example is a one pager; client side only; Two input boxes to get input of a weight and convert lb/kg. Got the conversion and the rest. Wishing the 'calc' button can fire by keyboard as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top