This is my first time really using HTML, Javascript and PHP.
This is part of a prototype for a project for my SW Eng. course.
The problem I am having is that the form is not going through the validation. The user is supposed to be able to search by either last name or SSN, so I have a 2 radio buttons corresponding to the 2 search fields, and based on the choice, the function will validate the chosen input. The problem is when I test the page, none of the alerts pop up, making me conclude that the function isn't even being executed, however the data is being passed to the php page.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>MVC Student Information System - Search</title>
<script type="text/javascript">
function validate(form){
if (form.radChoice.value == "S"){
alert("Branch 1 has executed");
var strSSN = String(form.SSN.value);
if (/\b\d{9}\b/.test(strSSN) == false){
alert("SSN must contain exactly 9 digits");
return false;
}
else{
return true;
}
}
else if (form.radChoice.value == "N"){
alert("Branch 2 has executed");
if (lName.value == NULL || lName.value == ""){
alert("Name cannot be blank.");
return false;
}
else{
return true;
}
}
else{
alert("This should not be happening");
return false;
}
}
</script>
</head>
<body>
<h1>MCV Student Information System</h1>
<h2>Welcome to the Administrative Add Student Page</h2>
<h4>Please select a search parameter and click the search button</h4>
<form action="adminSearch.php" name="search" method="post"
onsubmit="return validate(this);">
<input type="radio" name="radChoice" value="S" />SSN: <input type="text" name="SSN" /><br>
<input type="radio" name="radChoice" value="N" />Last Name:<input type="text" name="lName" /><br>
<input type="submit" name="btnSearch" value="Search" />
</form>
<h3><a href="adminMenu.html">Back to Administrative Menu</a></h3>
</body>
</html>