How to control which submit button to use when hit enter

M

Martin

Is there any way (using javascript) to "click" a specific "submit"
button when the user hits the <Enter> key?

From what I read, hitting <Enter> is supposed to send the form via the
"first" submit button on the page but I find that, in IE at least, my
server-side scripting doesn't receive any submit button.
 
M

Mike Duffy

Is there any way (using javascript) to "click" a specific "submit"
button when the user hits the <Enter> key?

From what I read, hitting <Enter> is supposed to send the form via the
"first" submit button on the page but I find that, in IE at least, my
server-side scripting doesn't receive any submit button.

I'm not sure about pre-picking a particular button, but why not just use
the same event handler for your default button AND the return key?

In the example, "dh" is the default form handler, which will execute if
button yy is pushed, or if the return key is pressed. "hh" will only be
called if button xx is pressed.

You can also designate other functions to fire when any particular key is
pressed, just by changing the value of 13.


<form name="myform" action="" method="post">

<input title="tt" type="text" name="inputbox" value="ib" maxLength="10"
size="10" onkeypress="if (event.keyCode==13) {dh(this.form);};" >

<input type="button" name="button" value="xx" onClick="hh(this.form);" >

<input type="button" name="button" value="yy" onClick="dh(this.form);" >

</form>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top