Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Seoul, Korea
    Posts
    329
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Please click the submit button instead of using enter key

    Code:
    <form action='action.htm'>
    
    <input type='text'>
    
    <input type='submit'>
    
    </form>
    With the code above, there are two ways to make it move to action.htm.

    (1) The one is clicking the buttton "submit."

    (2) The other is strikes the enter key after putting your mouse on the input text box.


    I like to make it (1) work, but (2) not work.


    If possible, I like to make it like the follow.

    if a user strikes the enter key after putting his or her mouse on the text input box, it pops an alert saying "Please click the submit button instead of using enter key."
    Last edited by joonstar; 12-10-2006 at 08:10 AM.
    Get my greedy up

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,314
    Thanks
    203
    Thanked 2,565 Times in 2,543 Posts
    function onKeyPress (e) {
    var keycode;
    if (window.event) {keycode = window.event.keyCode}
    else if (e) keycode = e.which;
    else return true;
    if (keycode == 13) {
    alert ("Please use the tab key (not the enter key) or click\nwith your mouse to move between the form fields.");
    return false;
    }
    return true;
    }
    if (document.layers) document.captureEvents(Event.KEYPRESS);
    document.onkeypress = onKeyPress;

    Glad to see that your greedy is still up!

  • #3
    Regular Coder
    Join Date
    Apr 2003
    Location
    Seoul, Korea
    Posts
    329
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Glad to see that your greedy is still up!
    My greedy is going up and down.

    Your code works fine. thank you.
    Get my greedy up

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Just remember that the only way that people without a mouse have to "click" on something is to press the enter key so if you block that for the submit button then you stop them from being able to submit the form at all.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •