View Full Version : Press enter key to click a specific submit button

10-27-2003, 03:12 AM

I have several "submit" buttons on a form. I want users to be able to hit the "enter" key to submit the form. The page used to "post" the information checks for specifically what form button was pushed to submit the form before executing the appropriate code. I am automatically submitting the page when the enter key is hit, but it is defaulting to the first option of executed code in the post page.

Example - I have an "update" button and a "delete" button on the form. On the post page, I first check to see if the delete button was hit. When I press enter on the form, it simply answers yes to the first question (did they click the delete button), and the code is executed. I really wanted to emulate that the update button was hit.

So -- is there a way to hit the enter button, and in the js code, mandate that it was the "update" button that was clicked?


Willy Duitt
10-27-2003, 06:26 AM
Try this (http://www.dynamicdrive.com/dynamicindex16/disableenter.htm).


10-27-2003, 01:29 PM
afraid of my answer at the ranch?

01-21-2009, 06:16 AM
PLEASE HELP ME!!! Lol, I'm dying here...
I have a similar problem, ok; here goes...

This is a problem that has been pestering me for a long time now.
I have written a simple code in HTML which uses frames; basically, when you type in something in the text-box, if it

recognizes it from the script it will take you to it's set page, and if it's doesn't, then it'll take you to another set page

informing the user that it doesn't recognize your entry.
It's like a ChatBot basically.

What I need help with though is two things:
1. my first issue is when you up on pressing the [Enter], or [Return] key it does nothing, and you instead have to click the

'Submit' button; what I want is to be able to press the [Enter] key within the text-box and it automatically clicking that

button for me (like a search engine or login page would, etc)

2. And my second problem is that, when I load up my page; I want my cursor to automatically be set in the text-box, like with

Google; so that as soon as you load up the page you can type something in, and it'll appear in the text-box automatically,

without you having to click the textbox first.

If you geniuses are able to solve this for me, I literally will love you forever. Haa ha
I'm not kidding, I have been trying to figure this out for ages, so I wish you the best in cracking a method.
Anyway, I would love to hear from you soon... All the best :) And a million thanks for reading/helping. :)


There are two frames, and one index to link them both together.
This is the 'header' frame, and all documents from this frame, shall be displayed in the 'main' frame.

Here's a copy of my code:


<meta http-equiv="Content-Language" content="en-gb">

<!-- Begin
function Login(){
var done=0;
var data=document.login.data.value;
if (data=="8") { parent.main.window.location="8.html"; done=1; }
if (done==0) { alert("Could you please rephrase that?"); }
// End -->

<base target="_self">


<form name=login>
<table width=225 border=0 cellpadding=3 style="border-collapse: collapse" bordercolor="#111111" cellspacing="0">
<p align="center"><input type=text name=data size="20"></td><td>
<p align="center"><input type=button value="Submit" onClick="Login()"></td></tr>


01-21-2009, 06:24 AM
Please don't double post. I answered both your questions in your OP.

06-09-2010, 09:34 AM
Hi James, if you haven't got any replies yet, then, I have got a solution for the first point u were asking for in the below line of your code;

Originally posted:
<p align="center"><input type=button value="Submit" onClick="Login()"></td></tr>

Modified one:
<p align="center"><input type=submit value="Submit" onClick="Login()"></td></tr>