Solved

Submitting the form upon pressing enter

Posted on 2008-11-02
6
228 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
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Obtaining data on ASP 8 28
Running a javascript project in WebStorm 2 25
How to control cache of some js files ? 7 39
..ignore the Question 1 7
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

861 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