Jump to content
xisto Community
kvarnerexpress

Enter Keypress Submits Wrong Button

Recommended Posts

Ive got a form, with a submit button on the left and a submit button on the right. By default on the enter keypress, the form submits the left submit button, but i want it to submit the right button. How would i accomplish this? kvarnerexpress

Share this post


Link to post
Share on other sites

You should only have one submit button (type="submit") and make the other button a normal button (type="button") which has its own onclick event handler..

Example:

<html><head><script language="JavaScript"><!--function doSubmit( e ){   var keyCode = (window.Event) ? e.which : e.keyCode;   if( keyCode == 13 ) document.forms[0].submit();}function doSomethingElse(){    alert("Something else");}//--></script></head><body><form name="MyForm"><input type="text" name="blah" value="" onkeypress="doSubmit(event)" /><input type="button" value="Some Button" onclick="doSomethingElse()" /><input type="reset" value="Clear" /><input type="submit" value="Submit" /></form></body></html>

I hope that helps!

Share this post


Link to post
Share on other sites

Or you could simply add an extra field to the code used to produce the submit button. Your submit button is probably <input type="submit" name="blah" value="Blah" />, but you can add an extra field that makes it so the user could click ALT then another letter or number to get it to work. For example:

 

<input type="submit" name="blah" value="blah" accesskey="r" />

 

would make it so if the user pressed down on ALT + 4, the button would b e clicked.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.