我有一个名为 Add 和 Search 的两个提交按钮。当我单击 Add submit 按钮时,它会使用定义的 validate 方法进行适当的验证。现在我有另一个搜索提交按钮,也定义了它的功能,但它不工作,我的意思是它没有做任何验证
<!DOCTYPE html>
<html>
<head>
<title>INFORMATION</title>
<script type="text/javascript">
function svalidate(){
if (document.myForm.firstname.value=="" && document.myForm.lastname.value=="" && document.myForm.age.value=="" && document.myForm.gender.value==""){
alert("Please enter any one value");
return false;
}
}
function validate() {
if (document.myForm.firstname.value==""){
alert("Please provide the firstname");
return false;
}
if (document.myForm.lastname.value=="" ){
alert("Please provide the lastname");
return false;
}
if (document.myForm.age.value=="" || isNaN(document.myForm.age.value) || document.myForm.age.value<1){
alert("Please provide the valid age in Integer");
return false;
}
if (document.myForm.gender.value=""){
alert("Please provide the gender");
return false;
}
}
</script>
</head>
<body>
<form action = "/~neeraj/cgi-bin/test.py" name="myForm" method="post">
<table cellspacing="3" cellpadding="2" border="1">
<tr>
<td> FirstName:* </td>
<td> <input type="text" name="firstname" /></td>
</tr>
<tr>
<td>LastName:* </td>
<td> <input type="text" name="lastname" /></td>
</tr>
<tr>
<td>Age:* </td>
<td><input type="text" name="age" /></td>
</tr>
<tr>
<td>Gender:* </td>
<td><input type="radio" name="gender" value="male" /> Male
<input type="radio" name="gender" value="female" /> Female</td>
</tr>
</table>
<br>
<input type="submit" name="submit" value="ADD" onclick="return(validate())">
<input type="reset" name="reset" value="RESET">
<input type="submit" name="search" formmethod="post" formaction="/~neeraj/cgi-bin/search.py" value="SEARCH" onclick="return(svalidate())">
</form>
</body>
</html>