Avatar of Paul Konstanski
Paul Konstanski
Flag for United States of America asked on

HTML Submit using Enter Key Default to Submit Button

I have a very simple form that has both a "Submit" and "Cancel" button. (See below)..

It includes some javascript that runs when a person hits the "Submit" button.

But if a person enters the email and then hits the "Enter" key instead, the POST treats it as if the "Cancel" button was hit instead of the "Submit"

What do I need to do so that the default action for hitting the "enter" key is the "Submit" button and not the "Cancel" button.

<form class="smallbox" id="reg" method="post" action="myfile.php">
	<p><label for="email">Email Address</label><input type="text" id="a_email" name="a_email" size="75" maxlength="75"></p>
	<p><label for="memb">Member ID</label><input type="text" id="memb" name="memb" size="25" maxlength="25"></p>
	<input type="hidden" name="action" value="looker">
  	<p align="center">
		<input type="button" name="subButton" value="Submit" class="bt_blue" onclick="doAct('reg', 'new')">&nbsp;&nbsp;
    	<input type="submit" id="cancel" name="canButton" value="Cancel" class="cancel">
  	</p>
</form>

Open in new window

JavaScriptHTMLPHP

Avatar of undefined
Last Comment
Paul Konstanski

8/22/2022 - Mon
SOLUTION
duncanb7

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
Chris Harte

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Paul Konstanski

ASKER
Nice straight forward solution. Thanks a heap.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy