?
Solved

HTML Submit using Enter Key Default to Submit Button

Posted on 2013-11-19
3
Medium Priority
?
647 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
Suggested Courses

765 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