Solved

Submitting the form upon pressing enter

Posted on 2008-11-02
6
229 Views
Last Modified: 2008-11-02
Hey experts,

   I have a form with a username and password textboxes and a submit button; what I want is that upon pressing the enter key in the password field that the form gets submitted (i.e. as if the user pressed the submit button); any help on how to do that?
0
Comment
Question by:mte01
[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
  • 2
  • 2
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
Andrej Pirman earned 200 total points
ID: 22860733
Any HTML form will by default submit when you press ENTER.

...except in case if you intentionally intercept "formname.onsubmit" event and trigger some predefined function.
0
 
LVL 20

Assisted Solution

by:chaitu chaitu
chaitu chaitu earned 150 total points
ID: 22860734
<input type="text" name="userId" onkeypress="checkEnter(this.form,event)">
<script>
function checkEnter(formObj,evt) {
  if (document.all) {
    if (event.keyCode==13) {
      formObj.submit();
    }
  }
  if (document.layers) {
    if (evt.which==13) {
      formObj.submit();
    }
  }
}
</script>
0
 
LVL 18

Expert Comment

by:Andrej Pirman
ID: 22860736
Thinking further...maybe you wanted to ask how to submit form ONLY after password is enterd, but not when username is entered?
You may go with "onsubmit" event and trigger JavaScript, which will check if both, username and password are entered, and only then do "formname.submit"
0
Industry Leaders: 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!

 
LVL 3

Author Comment

by:mte01
ID: 22860758
>>Labsy

Regarding your 1st comment, yeh, you're right, I am submitting the form in the js function that is put in the onClick of the Submit button (so that explains why the enter key is not working automatically), so instead I'll do this js function on the onSubmit event of the form. Your 2nd comment is not related to what I am doing.

>>chaituu

Yes, this code is good if the automatic way wasn't done; thanks for your post..
0
 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 22860769
mte01,
did your job is fulfilled or anything left?
0
 
LVL 3

Author Comment

by:mte01
ID: 22860818
Yes, now everything is working well with me; thanks Labsy & chaitu!
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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
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 …
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

749 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