onsubmit=“return false” has no effect on Internet Explorer 7/8 (form is still submitted)

后端 未结 14 1995
耶瑟儿~
耶瑟儿~ 2020-12-11 04:03

I have a form that will be submitted by javascript code triggered in \"onsubmit\" of the tag. Works fine on all browsers - but not on IE7/IE8.

What can I do?

<
相关标签:
14条回答
  • 2020-12-11 04:29
    document.forms.userFormRegisterr.onsubmit =  function(e){
        return false;
    };
    
    0 讨论(0)
  • 2020-12-11 04:33

    I think that the problem is in return false you need to return it from your 'onsubmit' function

    see example.

    This form will never be submitted in IE 7/8 as well.

     <form action="acknowledgement.html" method="get" onsubmit="verify();">
            <input type="submit" name="submit"
             VALUE="Submit"> 
            </form>
    
    <script language="javscript">
    function verify(){
    
    return false;
    }
    </script>
    

    Danny.

    0 讨论(0)
  • 2020-12-11 04:34

    I had the same error and when I turned on the console, it never came. So I figured out, it was the console, that wasnt known by the internet explorer as long as it is turned off. Simply add a dummy console to the window with the following code (if there isnt already one):

    var myconsole = {log : function(param){}}
    window.console = window.console || myconsole;
    

    With this you could get in trouble, if you want to have microsofts javascript console. Then just comment the lines out. But now, the console object is not undefined anymore on the whole site.

    0 讨论(0)
  • 2020-12-11 04:37

    In fact, because you write submitmyform();return false only submitmyform is evaluated.

    In the case of two commands, you will have to put them between braces like this

    {submitmyform();return false;}
    

    so that both are evaluated.

    0 讨论(0)
  • 2020-12-11 04:38

    The solution for us was to move the javascript event from "onsubmit" of the form to "onclick" of the submit button.

    <form action="/dosomething.htm" method="GET">
      [...]
      <input type="submit" value="Go" onclick="submitmyform();return false">
    </form>
    
    0 讨论(0)
  • 2020-12-11 04:38

    If you want IE to be standards compliant, you'll have to tell it which standard it's supposed to comply with in a declaration.

    Without one it's going to be endless frustration to get it to do what you want. With one, most of the frustration goes away because it starts working as every other browser.

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