By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,831 Members | 1,024 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,831 IT Pros & Developers. It's quick & easy.

Hitting the enter key

P: 2
The website i am running for our fraternities local website has a password page. and after inputing the proper password you have to actually click on the enter button....

How can i get it so all u have to do is hit the enter key on the keyboard?

here is the website...... if you click on the brothers only link on the side u will see where its at.

http://studentorg.stcloudstate.edu/pkt/
Oct 3 '08 #1
Share this Question
Share on Google+
4 Replies


Markus
Expert 5K+
P: 6,050
I guess it depends what browser you are using. You know, with that big ol' 'submit' button there, I don't think your frat brothers will be too stumped on submitting the password.
Oct 3 '08 #2

P: 2
yea its not really a matter of a problem just makes the page easier to use. we all know to click on it. Was just trying to find out a way to get it so all u have to do is hit the enter key. I have gone on it many times and every now and then just hit enter because im used to doing it on so many other pages.
Oct 3 '08 #3

codegecko
Expert 100+
P: 533
Hi there,

It's a case of capturing the event when a key is pressed, checking to see if it's the Enter key, and submitting the form, right?
Try adding this to your form:
Expand|Select|Wrap|Line Numbers
  1. <form onkeypress="checkSubmit(event)">
  2.  
And in the head of your document, add this:
Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript>
  2. <!--
  3. function checkSubmit(e)
  4.  
  5. if (window.event) { //For IE
  6.    switch (e.keyCode) {
  7.         case 13:
  8.             document.myform.submit();
  9.             return true;
  10.             break;
  11.         default:
  12.             return false;
  13.             break;
  14.     }
  15. } else if (e.which) {
  16.    switch (e.which) {
  17.         case 13:
  18.             document.myform.submit();
  19.             return true;
  20.             break;
  21.         default:
  22.             return false;
  23.             break;
  24.     }        
  25. }
  26. //--></script>
  27.  
Replace myform with the name of your form in the above code and it should work fine.
The above code is provided with a little help from W3Schools.

Hope this helps.

medicineworker

P.S. I moved your thread to the Javascript forum cause the answer is JS-based.
Oct 4 '08 #4

acoder
Expert Mod 15k+
P: 16,027
By default, both Firefox and IE will submit the form if you're still focused on the text box and press the enter key.
Oct 4 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.