<form action="Verification" method="post" onsubmit='return (if (document.getElementById("1").value===document.getElementById("2").value))' >
Name: <input type="text" name="name" required/><br>
Email: <input type='email' name='email' id="1" required/><br>
Confirm Email: <input type='email' name='confirm' id="2" required/><br>
<input type="submit" value="Sign Up" />
</form>
我想知道如果这两封电子邮件不相同,我是否可以停止提交表单。
提前致谢
答案 0 :(得分:1)
你会想要做一些比较两个值的javascript,如果它们不相同则返回false。给两个输入一个名称或按id获取值,然后执行以下onsubmit:
function validateForm() {
var x = document.forms["myForm"]["parentsEmail"].value;
var y = document.forms["myForm"]["parentsEmailConfirmation"].value;
if (x != y) {
alert("Let them know it's wrong here.");
return false;
}
//else finish submission process
}
答案 1 :(得分:0)
您应该使用jQuery验证 https://jqueryvalidation.org/equalTo-method/