Results 1 to 4 of 4

Thread: Form submit with Enter Key

  1. #1
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Angry Form submit with Enter Key

    Hello all, I'm curious if anyone has experienced this frustrating problem; When I make forms, some of them the Enter key works to submit the form in IE 8 and on some of the forms it does not. Am I missing something??
    Last edited by crobinson42; 03-01-2012 at 05:02 PM.

  2. #2
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Found this

    Code:
    <html>
    <head>
    <SCRIPT TYPE="text/javascript">
    <!--
    function submitenter(myfield,e)
    {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    
    if (keycode == 13)
       {
       myfield.submit();
       return false;
       }
    else
       return true;
    }
    //-->
    </SCRIPT>
    </head>
    <body>
    <FORM ACTION="processingpage" onKeyPress="return submitenter(this,event)">
    <input type="text"></input>
    </FORM>
    </body>
    </html>
    All you need to do is add this onKeyPress="return submitenter(this,event)" to your form tag and this

    Code:
    <SCRIPT TYPE="text/javascript">
    <!--
    function submitenter(myfield,e)
    {
    var keycode;
    if (window.event) keycode = window.event.keyCode;
    else if (e) keycode = e.which;
    else return true;
    
    if (keycode == 13)
       {
       myfield.submit();
       return false;
       }
    else
       return true;
    }
    //-->
    </SCRIPT>
    to the head of your document. It'll submit the form onkeypress enter(keycode 13).

    The srcipt was from here
    Keyboard1333

  3. The Following User Says Thank You to keyboard For This Useful Post:

    crobinson42 (02-29-2012)

  4. #3
    Join Date
    May 2010
    Location
    Sacramento, CA
    Posts
    91
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Default

    Thanks, I was hoping to not have to use script! I guess it's just a bug!?

  5. #4
    Join Date
    Mar 2011
    Posts
    2,144
    Thanks
    59
    Thanked 116 Times in 113 Posts
    Blog Entries
    4

    Default

    Yes I agree, it can be very frustrating...
    At least there's a fairly easy way out of it.

    If this thread is finished please set it to Resolved. You can do this by clicking edit on your first post, go advanced, prefixes resolved.

    Keyboard1333

Bookmarks

Posting Permissions

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