Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 重定向具有多个提交输入的表单_Javascript_Jquery_Html - Fatal编程技术网

Javascript 重定向具有多个提交输入的表单

Javascript 重定向具有多个提交输入的表单,javascript,jquery,html,Javascript,Jquery,Html,我有一个表单,其中包含3单独的输入,并带有“提交”类型 前两个输入在单击后输出一条消息,但最后一个输入应该重定向到另一个页面,但它没有这样做。我认为这是因为表单在到达JavaScript进行重定向之前正在提交和刷新页面 这是我的密码: FORM.php <form class="form" id="form" method="POST" enctype="application/x-www-form-urlencoded"> <br> <i

我有一个表单,其中包含3单独的输入,并带有“提交”类型

前两个输入在单击后输出一条消息,但最后一个输入应该重定向到另一个页面,但它没有这样做。我认为这是因为表单在到达JavaScript进行重定向之前正在提交和刷新页面

这是我的密码:

FORM.php

<form class="form" id="form" method="POST" enctype="application/x-www-form-urlencoded">
    <br>
         <input type="email" name="email" id="email" maxlength="80" value="<?php echo $email ?>" placeholder="Enter Your Email" /><br /><br>
        <input id="button4" type="submit" value="Get Security Question" name="submit2" style="cursor:pointer;"/><br> 
            <br><input type="password" name="securitya"id="securitya" maxlength="20" value="<?php echo $securitya ?>" placeholder="Enter Your Security Answer" /> <br />
        <br>
    <input id="button3"type="submit" value="Check Answer" name="submit" style="cursor:pointer;"/>
    <br>
        <br><input type="password" name="newpassword" id="newpassword" maxlength="20" placeholder="Enter Your New Password" /> <br />

    <br><input type="password" name="confirmpassword" id="confirmpassword" maxlength="20" placeholder="Re-Enter Your New Password" /> <br />

<br>
    <input id="button2" type="submit" value="Change Password" disabled="disabled" name="submit" style="cursor:pointer;"/>



在javascript中,将事件传递到click处理程序中,然后preventDefault()

“提交”按钮具有默认行为,因此您需要防止其默认行为,以便可以执行操作,然后使用window.location.href重定向


请尝试更改为
document.location='您的URL'

我刚刚尝试了这个默认方法,但它仍然没有重定向。数据是使用php从mySQL数据库中发送和检索的,我没有将其包括在本文中post@oggle0901请尝试更改为“document.location=”您的URL'@oggle0901不客气。我猜你在玩IE?由于某些原因,我总是需要在IE中使用document.locaiton,而window.location在其他地方都可以使用。令人惊讶的是,我使用的是ChromePrefix,请检查您的代码。您有不匹配的引号。它不会重定向,因为按钮被禁用。我有一个JavaScript函数,所以当所有字段都有内容时,按钮不再被禁用#恶作剧
jQuery(function(){
        $("#button2").click(function(){                                         
        $(".error").hide();
        var hasError = false;
        var passwordVal = $("#newpassword").val();
        var checkVal = $("#confirmpassword").val();
        if (passwordVal == '') {
            $("#newpassword").after('<span class="error" >Please enter a password.</span>');
            hasError = true;
        } else if (checkVal == '') {
            $("#confirmpassword").after('<span class="error">Please re-enter your password.</span>');
            hasError = true;
        } else if (passwordVal != checkVal ) {   
            $("#confirmpassword").after('<span id = "pass" class="error">Passwords do not match.</span>');
            hasError = true;
        }
        if(hasError == true) { return false; }
        else {

            $("#button2").after('<span class="error">Passwords accepted.</span>');

            window.location.href='adminsignin.php';
            }

    }); 
});
$("#butotn2").click(function(e) {
    e.preventDefault();
   ...
}