Solved

HTML Submit using Enter Key Default to Submit Button

Posted on 2013-11-19
3
611 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 50 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 100 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
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 …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

713 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