I have a submit button and search button in my html page. when i click submit it goes to the proper script. Now i have an search button in html, which also chacks the validation.I dont want the search button to have all this validation, only i need is to enter data in any one of this text field if search button is clicked. How can do i this using 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>