[英]JSP submits the form even though js returns false
我正在嘗試驗證表格。 只需嘗試確認密碼即可。 JS顯示警告,該函數返回false,但仍將表單提交到下一頁。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<script>
function validatePassword(){
var password=document.form1.password.value;
var cpassword=document.form1.cpassword.value;
if(password!=cpassword){
alert("Password Do not match");
return false;
}else{
return true;
}
}
</script>
</head>
<body>
<h1>Hello World!</h1>
<form name="form1" onsubmit="validatePassword();" action="login.jsp">
<table width="80%">
<tr>
<td style="text-align: center;width:40%">Password<font color="red">*</font>:</td>
<td style="text-align: center"><input type="text" name="password" required size="35"></td>
</tr>
<tr>
<td style="text-align: center">Confirm <font color="red">*</font>:</td>
<td style="text-align: center"><input type="text" name="cpassword" required size="35"></td>
</tr>
<input type="submit">
</form>
</body>
</html>
您的處理程序當前未返回任何內容,請按以下方式使用它:
onsubmit="return validatePassword();"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.