Web Analytics Made Easy -
StatCounter disable enter key - CodingForum

Announcement

Collapse
No announcement yet.

disable enter key

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • disable enter key

    How I can disable enter key for one submit button?

    Regards

  • #2
    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;

    Is that what you want?

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

    Comment


    • #3
      Look I have three radio buttons and one submit button just I want to disable the enter key for the submit button not for the radio buttons.

      (example of my radio buttons <input type="radio" name="Search" onclick="submit.this();">)

      Regards

      Comment


      • #4
        Assuming that your form is named"myform" and the submit button is named "submitit" then you could use the above code but replace

        if (document.layers) document.captureEvents(Event.KEYPRESS);
        document.onkeypress = onKeyPress;


        with

        myform.submitit.onkeypress = onKeyPress;

        Just substitute whatever names you gave your form and submit button.
        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.

        Comment

        Working...
        X