can anyone tell me why this does not work:
<div>
<table>
<FORM name="search_form" method='POST' onSubmit="return validate_form();" ACTION='jobsearch.php'>
<tr><td>keyword:</td><td >
<INPUT TYPE='TEXT' NAME='keyword'></td>
<td>Industry:</td><td >
<select name="cat_id">
<option value="">---select one---</option>
<option value="1">Accounting</option>
<option value="2">Administration</option>
<option value="3">Automation</option>
<option value="4">Banking</option>
<option value="5">Biotech</option>
<option value="6">Bussiness</option>
<option value="7">Construction</option>
<option value="8">Construction</option>
<option value="9">Consulting</option>
</select></td></tr>
<tr><td>city and state or zipcode: </td><td >
<INPUT TYPE='TEXT' NAME='place'></td></tr>
<tr ><td colspan="2"><input type="submit" value="Search"></td></tr>
</form>
</table>
</div>
the javascript containing the function validate_form was linked in the header section:
<HEAD>
<link href='style_sbdjobs.css' type='text/css' rel='stylesheet' />
<script src="reg_form.js"></script>
</HEAD>
the problem is when the submit button is clicked, the javascript function is not called instead the php function is called directly but i need the form to be validated first before it is sent to the server. here is what the javascript reg_form.js looks like:
function validate_form( )
{
valid = true;
if ( document.search_form.keyword.value == "" )
{
alert ( "Please type in a keyword." );
valid = false;
break;
}
if ( document.search_form.cat_id.selectedIndex == 0 )
{
alert ( "Please select an industry." );
valid = false;
break;
}
if ( document.search_form.place.value == "" )
{
alert ( "Please type in a zipcode or city and state." );
valid = false;
break;
}
return valid;
}