In IE8 enter key in a form does not work

后端 未结 14 2358
失恋的感觉
失恋的感觉 2020-12-17 08:55

I have a problem that in IE8 the enter does not work to submit a form. I have generated a test page to expose this problem. It seems that displaying the form in the on

相关标签:
14条回答
  • 2020-12-17 09:29

    Found a working solution.

    Make the submit button invisible instead of using display:none;

    input#submit {
    color: transparent;
    background: transparent;
    border: 0px;
    }
    
    0 讨论(0)
  • 2020-12-17 09:33

    For any future users stumbling upon this question:

    What worked for me was adding a DOCTYPE:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    0 讨论(0)
  • 2020-12-17 09:34

    I think everthing is much more complicated than you think...

    when a form's display value is set to none with a css class or just with a style attribute on page inital, hitting the enter key in a text field does not work only if you have more than one input field with text type... if you have one text field it works fine.. if you have more than one, it does not fire form submission...

    Here i made a demo...

    Works Fine (Normal Form) http://yasinergul.com/stackoverflow/ie8-enter-key-bug/one.html

    Works Fine (Form hidden & set back visible but it's with one text input) http://yasinergul.com/stackoverflow/ie8-enter-key-bug/two.html

    Does Not Work (Form hidden & set back visible but it's with two text input) http://yasinergul.com/stackoverflow/ie8-enter-key-bug/three.html

    i think the best approach is to give a .hidden class to the object but not setting display:none for this css selector. you can make it hidden with jquery like

    $(".hidden").hide();

    as the page loads the form is shown for miliseconds but gets hidden after jquery works...

    0 讨论(0)
  • 2020-12-17 09:40

    You may want to add a onkeyup event to your input boxes so that if you hit an enter in the input box then it will also submit.

    As CodePartizan mentioned, you need the focus on the button otherwise, so if you tab over to the button, or click on it, it seems to work for me also.

    0 讨论(0)
  • $("form input").keypress(function (e) {
       if(e.which === 13) {
          $("form").submit();
       }
    });
    

    Above is a proper fix. Ref: IE Not submitting my form on enter press of enter key?

    0 讨论(0)
  • 2020-12-17 09:44

    I had the same issue with ie and none of the solutions helped until I read this:

    http://www.rachaelarnold.com/dev/archive/enter-key-form-submission-bug#ixzz2Y5Zwgj2k

    my form only had one input field....duh! :)

    0 讨论(0)
提交回复
热议问题