Hitting the enter key

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • marine33
    New Member
    • Oct 2008
    • 2

    #1

    Hitting the enter key

    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.

  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    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.

    Comment

    • marine33
      New Member
      • Oct 2008
      • 2

      #3
      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.

      Comment

      • JamieHowarth0
        Recognized Expert Contributor
        • May 2007
        • 537

        #4
        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:
        Code:
        <form onkeypress="checkSubmit(event)">
        And in the head of your document, add this:
        Code:
        <script type="text/javascript>
        <!--
        function checkSubmit(e)
        
        if (window.event) { //For IE
           switch (e.keyCode) {
                case 13:
                    document.myform.submit();
                    return true;
                    break;
                default:
                    return false;
                    break;
            }
        } else if (e.which) {
           switch (e.which) {
                case 13:
                    document.myform.submit();
                    return true;
                    break;
                default:
                    return false;
                    break;
            }        
        }
        //--></script>
        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.

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          By default, both Firefox and IE will submit the form if you're still focused on the text box and press the enter key.

          Comment

          Working...