我在我的html頁面中有一個提交按鈕和搜索按鈕。當我點擊提交它去適當的腳本。現在我在html中有一個搜索按鈕,它也會檢查驗證。我不希望搜索按鈕具有所有這些驗證,只需要在單擊搜索按鈕時在該文本字段中的任何一箇中輸入數據。我該如何使用JavaScript?如何使用兩個提交按鈕清除驗證問題?
<!DOCTYPE html>
<html>
<head>
<title>INFORMATION</title>
<script type="text/javascript">
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" onsubmit="return(validate())">
<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="SUBMIT">
<input type="reset" name="reset" value="RESET">
<input type="submit" name="search" formmethod="post" formaction="/~neeraj/cgi-bin/search.py" value="SEARCH">
</form>
</body>
</html>
點擊搜索按鈕,當你想要什麼? – yilmazburk
如果搜索按鈕被點擊,它應該跳轉到另一個腳本,繞過所有的驗證 –