Solved

Submitting the form upon pressing enter

Posted on 2008-11-02
6
226 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
  • 2
  • 2
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
Andrej Pirman earned 200 total points
Comment Utility
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
Comment Utility
<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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Author Comment

by:mte01
Comment Utility
>>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
Comment Utility
mte01,
did your job is fulfilled or anything left?
0
 
LVL 3

Author Comment

by:mte01
Comment Utility
Yes, now everything is working well with me; thanks Labsy & chaitu!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now