[removed].href not working in form onsubmit

后端 未结 4 1086
悲&欢浪女
悲&欢浪女 2020-12-08 23:35

So i have a form, and onsubmit=\"return reg_check(this)\" where reg_check() is a javascript function in the header which is supposed to check the f

4条回答
  •  暖寄归人
    2020-12-08 23:59

    You need to return false; from your reg_check function and then in your onsubmit, change it to:

    onsubmit="return reg_check(this);"
    

    This will cancel the form submission. And if you want to let the form submit as normal, just return true from reg_check.

    Edit (to be more clear you need to add return false; from your function):

    function reg_check(myForm) {
        alert("before redirect..");
        window.location.href = "http://localhost/main.php?width=" + screen.width + "&height=" + screen.height;
        return false;
    }
    

提交回复
热议问题