Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HTML Submit using Enter Key Default to Submit Button

Posted on 2013-11-19
3
Medium Priority
?
676 Views
Last Modified: 2013-11-19
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

0
Comment
Question by:pkonstan1
3 Comments
 
LVL 13

Assisted Solution

by:duncanb7
duncanb7 earned 200 total points
ID: 39659730
Is it type of  submit button that should be submit intead of button or your typing mistake ?

Duncan

<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="submit" name="subButton" value="Submit" class="bt_blue" onclick="doAct('reg', 'new')">&nbsp;&nbsp;
    	<input type="button" id="cancel" name="canButton" value="Cancel" class="cancel">
  	</p>
</form>

Open in new window

0
 
LVL 17

Accepted Solution

by:
Chris Harte earned 400 total points
ID: 39659749
The input type for cancel is submit and the input type for submit is button. This should be the other way round

        <input type="submit" name="subButton" value="Submit" class="bt_blue" onclick="doAct('reg', 'new')">&nbsp;&nbsp;
        <input type="button" id="cancel" name="canButton" value="Cancel" class="cancel">

Open in new window

0
 

Author Closing Comment

by:pkonstan1
ID: 39659915
Nice straight forward solution. Thanks a heap.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question