Auto button when user hits the Enter key

Reply

Join Date: Jun 2009
Posts: 38
Reputation: nigelburrell is an unknown quantity at this point 
Solved Threads: 0
nigelburrell nigelburrell is offline Offline
Light Poster

Auto button when user hits the Enter key

 
0
  #1
Jun 7th, 2009
Hi

I am developing a login screen for my website, with usercode and password fields, and a Login button.

I need to know how I can make the Login button automatically submit when the user hits the Enter key in either field (as apposed to the user clicking the Login button, which already works).

Thanks

Nigel
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 340
Reputation: Josh Connerty is an unknown quantity at this point 
Solved Threads: 26
Josh Connerty's Avatar
Josh Connerty Josh Connerty is offline Offline
Posting Whiz

Re: Auto button when user hits the Enter key

 
0
  #2
Jun 7th, 2009
Can you post the form it is most likley the way you have structured the form.
Posts should be like mini-skirts, long enough to cover enough, but not too long that you cover too much.

My Liveperson: http://liveperson.com/josh-connerty/
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Auto button when user hits the Enter key

 
0
  #3
Jun 7th, 2009
Browsers do that by default. They will submit the form you're currently on when you hit enter(unless you're in a textbox) you don't have to do anything special.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 77
Reputation: Tulsa is an unknown quantity at this point 
Solved Threads: 15
Tulsa's Avatar
Tulsa Tulsa is offline Offline
Junior Poster in Training

Re: Auto button when user hits the Enter key

 
0
  #4
Jun 11th, 2009
hi
i think you want that login form submit that user press enter key after entering password right.
so i pu one example here where i call javascript function on keypress of textbox
  1. <input name="login2" type="password" class="form" id="login2" maxlength="30" style="width:180" onKeyPress="return entersubmit(this,event)"/>
  1. <script type="text/javascript">
  2. function entersubmit(field,e)
  3. {
  4. var keycode;
  5. if (window.event) keycode = window.event.keyCode;
  6. else if (e) keycode = e.which;
  7. else return true;
  8.  
  9. if (keycode == 13)
  10. {
  11. //alert('hi');
  12. if(Email.validate() && Passwd.validate())
  13. {
  14. field.form.action="userlogin";
  15. field.form.submit();
  16. return false;
  17. }
  18. }
  19. else
  20. return true;
  21. }
  22.  
  23. </script>

Thanks
"Be honest"
"Confidence is everything"
Reply With Quote Quick reply to this message  
Join Date: Oct 2007
Posts: 78
Reputation: navi17 is an unknown quantity at this point 
Solved Threads: 5
navi17 navi17 is offline Offline
Junior Poster in Training

Re: Auto button when user hits the Enter key

 
0
  #5
Jun 11th, 2009
yes there is no need of such code.
when you click on enter in textbox forms is automatically submitted.
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 77
Reputation: Tulsa is an unknown quantity at this point 
Solved Threads: 15
Tulsa's Avatar
Tulsa Tulsa is offline Offline
Junior Poster in Training

Re: Auto button when user hits the Enter key

 
0
  #6
Jun 12th, 2009
hi
Yes
when we click on enter in textbox forms is automatically submitted only in "google chrome" browser
so for i.e and mozila browser we need to use this type of code as per my view..

Thanks
"Be honest"
"Confidence is everything"
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 340
Reputation: Josh Connerty is an unknown quantity at this point 
Solved Threads: 26
Josh Connerty's Avatar
Josh Connerty Josh Connerty is offline Offline
Posting Whiz

Re: Auto button when user hits the Enter key

 
0
  #7
Jun 12th, 2009
No you don't...

At least I don't...

Should do it fine, I presume nigelburrell (if he is still alive) has made a little cock up in his form, the idea is that it submits the current form...
Posts should be like mini-skirts, long enough to cover enough, but not too long that you cover too much.

My Liveperson: http://liveperson.com/josh-connerty/
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 38
Reputation: nigelburrell is an unknown quantity at this point 
Solved Threads: 0
nigelburrell nigelburrell is offline Offline
Light Poster

Re: Auto button when user hits the Enter key

 
0
  #8
Jun 15th, 2009
Originally Posted by Tulsa View Post
hi
i think you want that login form submit that user press enter key after entering password right.
so i pu one example here where i call javascript function on keypress of textbox
  1. <input name="login2" type="password" class="form" id="login2" maxlength="30" style="width:180" onKeyPress="return entersubmit(this,event)"/>
  1. <script type="text/javascript">
  2. function entersubmit(field,e)
  3. {
  4. var keycode;
  5. if (window.event) keycode = window.event.keyCode;
  6. else if (e) keycode = e.which;
  7. else return true;
  8.  
  9. if (keycode == 13)
  10. {
  11. //alert('hi');
  12. if(Email.validate() && Passwd.validate())
  13. {
  14. field.form.action="userlogin";
  15. field.form.submit();
  16. return false;
  17. }
  18. }
  19. else
  20. return true;
  21. }
  22.  
  23. </script>

Thanks
Thanks for your code Tulsa, it works great.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 38
Reputation: nigelburrell is an unknown quantity at this point 
Solved Threads: 0
nigelburrell nigelburrell is offline Offline
Light Poster

Re: Auto button when user hits the Enter key

 
1
  #9
Jun 15th, 2009
Originally Posted by Josh Connerty View Post
No you don't...

At least I don't...

Should do it fine, I presume nigelburrell (if he is still alive) has made a little cock up in his form, the idea is that it submits the current form...
What I found is that if the form contains only one textbox, then hitting Enter worked. But the moment I included two or more textboxes, in this case, a username and password textbox, then I needed the OnKey trigger code on the password textbox. I call the javascript from this to submit the current form and it works well now.

Thanks for your help.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 9
Reputation: 1337cookie is an unknown quantity at this point 
Solved Threads: 2
1337cookie 1337cookie is offline Offline
Newbie Poster

Re: Auto button when user hits the Enter key

 
1
  #10
Jun 15th, 2009
Using JavaScript is excessive as all HTML forms should submit when pressing enter (Provided they are setup properly). If you post the source of your form. I'm sure someone here (perhaps myself) can help fix it.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC