943,779 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2859
  • PHP RSS
You are currently viewing page 1 of this multi-page discussion thread
Jun 7th, 2009
0

Auto button when user hits the Enter key

Expand Post »
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
Similar Threads
Reputation Points: 11
Solved Threads: 0
Light Poster
nigelburrell is offline Offline
38 posts
since Jun 2009
Jun 7th, 2009
0

Re: Auto button when user hits the Enter key

Can you post the form it is most likley the way you have structured the form.
Reputation Points: 31
Solved Threads: 27
Unverified User
Josh Connerty is offline Offline
342 posts
since Apr 2009
Jun 7th, 2009
0

Re: Auto button when user hits the Enter key

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.
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Jun 11th, 2009
0

Re: Auto button when user hits the Enter key

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
PHP Syntax (Toggle Plain Text)
  1. <input name="login2" type="password" class="form" id="login2" maxlength="30" style="width:180" onKeyPress="return entersubmit(this,event)"/>
PHP Syntax (Toggle Plain Text)
  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
Reputation Points: 13
Solved Threads: 15
Junior Poster in Training
Tulsa is offline Offline
77 posts
since May 2009
Jun 11th, 2009
0

Re: Auto button when user hits the Enter key

yes there is no need of such code.
when you click on enter in textbox forms is automatically submitted.
Reputation Points: 15
Solved Threads: 6
Junior Poster
navi17 is offline Offline
118 posts
since Oct 2007
Jun 12th, 2009
0

Re: Auto button when user hits the Enter key

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
Reputation Points: 13
Solved Threads: 15
Junior Poster in Training
Tulsa is offline Offline
77 posts
since May 2009
Jun 12th, 2009
0

Re: Auto button when user hits the Enter key

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...
Reputation Points: 31
Solved Threads: 27
Unverified User
Josh Connerty is offline Offline
342 posts
since Apr 2009
Jun 15th, 2009
0

Re: Auto button when user hits the Enter key

Click to Expand / Collapse  Quote originally posted by Tulsa ...
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
PHP Syntax (Toggle Plain Text)
  1. <input name="login2" type="password" class="form" id="login2" maxlength="30" style="width:180" onKeyPress="return entersubmit(this,event)"/>
PHP Syntax (Toggle Plain Text)
  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.
Reputation Points: 11
Solved Threads: 0
Light Poster
nigelburrell is offline Offline
38 posts
since Jun 2009
Jun 15th, 2009
1

Re: Auto button when user hits the Enter key

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.
Reputation Points: 11
Solved Threads: 0
Light Poster
nigelburrell is offline Offline
38 posts
since Jun 2009
Jun 15th, 2009
1

Re: Auto button when user hits the Enter key

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.
Reputation Points: 11
Solved Threads: 2
Newbie Poster
1337cookie is offline Offline
9 posts
since Jun 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Send email from PHP
Next Thread in PHP Forum Timeline: WordPress scope???





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC