简体   繁体   中英

submit form on 'enter' in IE “web browser”

having a problem with the number one browser for downloading another browser...IE

IE8 fails to submit when you hit enter in a form. here is what i use:

function submitOnEnter() {
    if (browserName=="Microsoft Internet Explorer")
    {
        var key;

        if (window.event){
            key = window.event.keyCode; //IE
        }

        if(key == 13){
          document.forms['myform'].submit();
        }
    }
}

and this is located on the text input :

 onkeyup="submitOnEnter()"

The form seems to submit when i press enter twice?? but not once.

Can you help?

Okay guys, i fixed it using....

  <!-- Fix for IE bug (One text input and submit, disables submit on pressing "Enter") -->    
  <div style="display:none">                 
  <input type="text" name="hiddenText"/>     
  </div> 

Weird eh? Maybe this will work for some of you and not others. some solutions didnt work for me, this one did.

Submit works when pressing ENTER when there is a submit button present in the form <input type="submit"> . You can hide the button if you want. No need to intercept keystrokes.

My problem was that i checked for the submit button. But IE seems not to send the submits in the $_POST array. Adding a hidden field solved my problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM