Link to home
Start Free TrialLog in
Avatar of Paul Konstanski
Paul KonstanskiFlag 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

SOLUTION
Avatar of duncanb7
duncanb7

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of Chris Harte
Chris Harte
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Paul Konstanski

ASKER

Nice straight forward solution. Thanks a heap.