[英]JavaScript - disable submit button
My function isn't able to disable the submit button (id="mySubmit"), the rest works fine. 我的功能无法禁用“提交”按钮(id =“ mySubmit”),其余功能正常。 (The function is called on "onkeyup")
(该函数在“ onkeyup”上调用)
I am trying to disable it if the values of the two password fields do not match. 如果两个密码字段的值不匹配,我试图禁用它。
function check_match() { var pw1 = document.getElementById("one").value; var pw2 = document.getElementById("two").value; if (pw1 == pw2) { document.getElementById("error_match").style.color = "green"; document.getElementById("error_match").innerHTML = "paswords match"; document.getElementById("mySubmit").disabled = false; } else { document.getElementById("error_match").style.color = "red"; document.getElementById("error_match").innerHTML = "passwords do not match"; document.getElementById("mySubmit").disabled = true; } }
<form action="#" class="userregister" method="POST"> <label for="email"><b>E-Mail</b></label> <input type="email" placeholder="Enter E-Mail" name="email" required /> <!--Password1--> <label for="password"><b>Passwort</b></label> <input type="password" placeholder="Enter Password" name="password" id="one" pattern="(?=.*\\d)(?=.*[az])(?=.*[AZ]).{8,}" onkeyup="check_match();" required /> <span id="error"></span> <!--Password2--> <label for="password2"><b>repeat Password</b></label> <input type="password" placeholder="Enter Password again" name="password2" id="two" onkeyup="check_match();" required /> <span id="error_match"></span><br /> <input type="checkbox" id="conditionbox" onclick="conditioncheck()" checked required> <a href="conditions.php" style="text-decoration: none">conditions </a>accepted<br /> <span id="message" class="agberror"></span> <button type="submit" id="mySubmit" name="reg">Register</button> </form>
I put the script part at the end of the body tag 我将脚本部分放在body标签的末尾
You have just use === instead ==. 您只需使用===代替==。
3 == '3' // true - because value is same 3 === '3' //false - because datatype is not same 3 =='3'// true-因为值相同3 ==='3'// false-因为数据类型不同
always use === strict equal 始终使用===严格等于
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.