homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

Form submit on enter
OK its an easy one - but it is friday and I want to home

 4:00 pm on Oct 1, 2004 (gmt 0)

Quick question as my brain has taken leave of it's memory. How do I get a form to submit when a user hits enter, not just by clicking the button.

ta, Limbo



 4:16 pm on Oct 1, 2004 (gmt 0)

How about using
onkeypress on the input fields:

function submitMe() {
if (window.event.keyCode == 13)

Then in your HTML:

<input type="text" ... onKeyPress="submitMe()">

This is off the top of my head and may be way off!



 4:20 pm on Oct 1, 2004 (gmt 0)

Depending on how complex your form is, it should be able to be submitted by the user pressing "Enter" while focus is on any text field, by default.

You should only need to put a script to trigger the submit function in fields which are not of the type="text".


 4:24 pm on Oct 1, 2004 (gmt 0)

The behaviour of browsers should be that if the form only has one input then hitting return should submit the form. However, behaviour varies widely between the browsers!


 11:09 pm on Oct 1, 2004 (gmt 0)

I'm half asleep as I write this, but I think it is as simple as setting type="submit".

I wrote a demo page some months ago (with three forms on a single page) and I think I tested it on IE, FF and Opera and all behaved correctly.



 10:09 am on Oct 8, 2004 (gmt 0)


I do apologise, forgot to say thanks for the replies.

Unfortunately none of the suggestions seemed to work. I have aquired the page from another.


<form name="frm">
Enter password
<input type="password" name="pswd" size="6">
<input name="button" type="button" onsubmit="loadpage(target)" onClick="loadpage(target)" value="Proceed">

Thanks, Limbo.


 2:03 pm on Oct 8, 2004 (gmt 0)

Change type="button" to type="submit" and delete the OnClick value.

Finally, set <FORM OnSubmit="return processForm();"> where processForm is the name of your validation function. It must return true to permit form submission to proceed.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved