简体   繁体   English

在Chrome中,JavaScript提交功能只能运行一次

[英]In Chrome JavaScript submit function works only once

I have created a signup form. 我已经创建了一个注册表单。 If all three fields have correct values then I submit the form. 如果所有三个字段的值都正确,那么我将提交表单。 Otherwise error displays and the form is not submitted. 否则将显示错误,并且不会提交表单。

function checkUserValidation() {
    if ((validateEmail() == true) && (validatePassword() == true) && (validateRepeatPassword() == true)) {
        document.getElementById('signup-form').submit(); // This works only first time in chrome..
        return true;
    } else {
        return false;
    }
}

<form id="signup-form">
    <div class="container">
        <label> <b>Email</b> </label>
        <input id="signup-email" class="signup_field" type="text" name="signup-email" required onfocusout="validateEmail()" />
        <label id="Invalid-Signup-Email" style="visibility:hidden;"></label>
        <label> <b>Password</b> </label>
        <input id="signup-pass" class="signup_field" type="password"  name="signup-pass" required onfocusout="validatePassword()" />
        <label id="Invalid-Signup-Pass" style="visibility:hidden;"></label>
        <label> <b>Confirm your Password</b> </label>
        <input id="signup-rep-pass" class="signup_field" type="text"  name="signup-rep-pass" required  onfocusout="validateRepeatPassword()" />
        <label id="Invalid-Signup-Rep-Pass" style="visibility:hidden;"></label>
    </div>
    <div class="clearfix">
        //following code does not work properly
        <input class="signupbtn" type="button" name="signup" value="Sign Up" onclick="return checkUserValidation(); submit()" /> 
    </div>
</form>

Problem is the submit function works only once in Chrome (working fine in IE). 问题是submit功能在Chrome中只能使用一次(在IE中可以正常使用)。 Next time the form does not submit even if I enter all the correct values. 下次即使我输入所有正确的值,表单也不会提交。

Searched and tried solutions mentioned on Stack Overflow but nothing worked. 搜索并尝试了堆栈溢出中提到的解决方案,但没有任何效果。

Look at your submit input, you are returning a value return checkUserValidation(); 查看您的提交输入,您将返回一个值return checkUserValidation(); and after you're submitting submit(); 在您提交submit();

<input class="signupbtn" type="button" name="signup" value="Sign Up" onclick="return checkUserValidation(); submit()" /> 

We can't put anything after return statement because the execution die or finish at that point. 我们不能在return语句后放置任何内容,因为执行会在此时死掉或结束。

I guess you're trying to do something like: 我想您正在尝试执行以下操作:

if(checkUserValidation() == true){ submit(); }

I recommend you to make a JS file (don't use inline JS) and then try with the if statement above 我建议您制作一个JS文件(不要使用内联JS) ,然后尝试上面的if语句

First of all "validateEmail", "validatePassword" and "validateRepeatPassword" are not defined anywhere. 首先,“ validateEmail”,“ validatePassword”和“ validateRepeatPassword”未在任何地方定义。

Secondly, when you are already submitting the form after checking all the field level validation, then what's the point of having the return true statement; 其次,当您在检查所有字段级别的验证之后已经提交表单时,那么使用return true语句的意义何在;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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