Please help I've written this code and it works until i asked it to check if the radio buttons were checked and if none of them were checked to come up with an error alert and if one of them was checked to ask the user to confirm if it was the level they wanted. Please help!!
<head>
<title>Exam entry</title>
<script language="javascript" type="text/javascript">
var level;
result = true;
msg="";
function validateForm()
{
var result = true;
msg="";
if (document.ExamEntry.name.value=="")
{
msg+="You must enter your name \n";
document.ExamEntry.name.focus();
document.getElementById('name').style.color="red";
result = false;
}
if (document.ExamEntry.subject.value=="")
{
msg+="You must enter the subject \n";
document.ExamEntry.subject.focus();
document.getElementById('subject').style.color="red";
result = false;
}
//this will check to see if the examNo field is filled out
if (document.ExamEntry.examNo.value=="")
{
msg+="You must enter the exam number \n";
document.ExamEntry.examNo.focus();
document.getElementById('examNo').style.color="red";
result = false;
}
//this will check to see if what you've typed in the examNo field is 4 characters long
if (document.ExamEntry.examNo.value.length !=4 )
{
msg+="Your exam number must be 4 numbers long \n";
document.ExamEntry.examNo.focus();
document.getElementById('examNo').style.color="red";
result = false;
}
var level = 0;
lvlResult = true;
answer;
if (document.ExamEntry.group1[0].checked==true)
{
level = document.ExamEntry.group1[0].value;
confirmLevel(level);
}
if (document.ExamEntry.group1[1].checked==true)
{
level = document.ExamEntry.group1[1].value;
confirmLevel(level);
}
if (document.ExamEntry.group1[2].checked==true)
{
level = document.ExamEntry.group1[2].value;
confirmLevel(level);
}
if(msg=="")
{
return result;
}
else
{
alert(msg);
return result;
}
}
function confirmLevel()
{
var answer;
answer=confirm("You have chosen "+ level + " is this correct?")
if (answer==0)
{
level = 0;
}
else
{
alert("Please choose an exam level");
document.ExamEntry.level.focus();
document.getElementById('level').style.color="red";
lvlResult = false;
return lvlResult;
}
}
</script>
</head>
<body>
<h1>Exam Entry Form</h1>
<form name="ExamEntry" method="post" action="success.htm">
<table width="50%" border="0">
<tr>
<td id="name">Name</td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td id="subject">Subject</td>
<td><input type="text" name="subject" /></td>
</tr>
<!--the following section of code puts in a new row and 2 new cells in the table one with Exam Number written in it the other with a text field in it -->
<tr>
<td id="examNo">Exam Number</td>
<td><input type="text" name="examNo" /></td>
</tr>
<tr>
<td id="level">Level</td>
<td><input type="radio" name="group1" id="GCSE" value="GCSE" onClick="return confirmLevel">GCSE<input type="radio" name="group1" id="AS" value="AS" onClick="return confirmLevel">AS<input type="radio" name="group1" id="A2" value="A2" onClick="return confirmLevel">A2</td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit" onClick="return validateForm();" /></td>
<td><input type="reset" name="Reset" value="Reset" /></td>
</tr>
</table>
</form>
</body>