我一直在尝试验证输入的2个密码,但是即使我输入了错误的密码,JavaScript函数也不会执行
userregistration.jsp
function matchpass() {
var firstpassword = document.myform.psw.value;
var secondpassword = document.myform.psw - repeat.value;
if (firstpassword == secondpassword) {
return true;
} else {
alert("password must be same!");
return false;
}
}
<form name="myform" action="RegisterControllerServlet" method="post">
<br><br>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<label for="psw-repeat"><b>Repeat Password</b></label>
<input type="password" placeholder="Repeat Password" name="psw-repeat" required>
<hr>
<button type="submit" class="registerbtn" onSubmit="return matchpass();">Register</button>
</div>
我希望能够验证两个密码
答案 0 :(得分:0)
删除#include "Message.h"
并将return
更改为onSubmit
onclick
答案 1 :(得分:0)
function matchpass() {
var firstpassword = document.myform.psw.value;
var secondpassword = document.myform.psw_repeat.value;
if (firstpassword == secondpassword) {
document.myform.submit();
} else {
alert("password must be same!");
}
}
<form name="myform" action="RegisterControllerServlet" method="post">
<br><br>
<label for="psw"><b>Password</b></label>
<input type="password" placeholder="Enter Password" name="psw" required>
<label for="psw-repeat"><b>Repeat Password</b></label>
<input type="password" placeholder="Repeat Password" name="psw_repeat" required>
<hr>
</form>
<button class="registerbtn" onclick="matchpass();">Register</button>