Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > How to control which submit button to use when hit enter

Reply
Thread Tools

How to control which submit button to use when hit enter

 
 
Martin
Guest
Posts: n/a
 
      04-10-2009
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.
 
Reply With Quote
 
 
 
 
Mike Duffy
Guest
Posts: n/a
 
      04-10-2009
Martin <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> 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>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
capturing from text area Shft+Enter, Control+Enter, Alt+Enter and browser issue. HopfZ Javascript 0 08-28-2006 10:11 AM
Form submit in textbox when enter key hit William Buchanan ASP .Net 2 04-07-2006 10:24 AM
Enter Key H*ll, control enter key submit button BrianDH ASP .Net Web Controls 3 01-12-2005 08:29 PM
Form submit - hitting enter does not trigger Submit button ASP General 2 10-25-2004 03:37 PM



Advertisments