Hello All,
Trying to figure out how to validate a series of questions on an online test. I am thinking that VB or Javascript is the best route, but your input may make a difference. The site i am working with is using .asp.
Their are 30 multiple choice questions. Each will have have 3 or 4 checkboxes where the test taker will choose only 1 answer per question. Anybody have any ideas as to the best way to validate that each question has at least one answer checked?
This form below has the functions i am trying to obtain, but does not send the results. I ge the email, but no results.
<html>
<head>
<title>Registration Form</title>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function validate() {
var theMessage = "Please complete the following: \n-----------------------------------\n";
var noErrors = theMessage
// make sure field is not blank
if (document.form1.name.value=="") {
theMessage = theMessage + "\n --> Your First Name";
}
// make sure field is not blank
if (document.form1.name1.value=="") {
theMessage = theMessage + "\n --> Your Last Name";
}
// Make sure at least 1 checkbox is checked
var multiCheckbox = false;
for (i = 0; i < document.form1.session1.length; i++) {
if (document.form1.session1[i].checked)
multiCheckbox = true; }
if (!multiCheckbox) {
theMessage = theMessage + "\n --> No answere for question 1";
}
// Make sure at least 1 checkbox is checked
var multiCheckbox = false;
for (i = 0; i < document.form1.session2.length; i++) {
if (document.form1.session2[i].checked)
multiCheckbox = true; }
if (!multiCheckbox) {
theMessage = theMessage + "\n --> No answere for question 2";
}
// If no errors, submit the form
if (theMessage == noErrors) {
return true;
} else {
// If errors were found, show alert message
alert(theMessage);
return false;
}
}
// End -->
</script>
</head>
<body>
<table border="1" width="100%">
<tr>
<td width="33%"> </td>
<td width="33%"><form name="form1" action="cgi-bin/sendmail_mike.asp" onSubmit="return validate(this);">
<table width="300" border="0" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#cccccc">
<table width="100%" border="0" cellpadding="3" cellspacing="1">
<tr bgcolor="#FFFFFF">
<td align="center">Registration Form</td>
</tr>
<tr bgcolor="#FFFFFF">
<td>First Name:<!-- field cannont be left blank --><br>
<input type="Text" name="name" size="20"></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Last Name:<!-- field cannont be left blank --><br>
<input type="Text" name="name1" size="20">
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td></td>
</tr>
<tr bgcolor="#FFFFFF">
<td>Which session(s) will you attend:<!-- field cannont be left blank --><br>
<input name="session1" type="checkbox" value="morning">Morning<br>
<input name="session1" type="checkbox" value="afternoon">Afternoon<br>
<input name="session1" type="checkbox" value="afternoon">Afternoon<br>
<input name="session1" type="checkbox" value="evening">Evening
<p>Which session(s) will you attend:<!-- field cannont be left blank --><br>
<input name="session2" type="checkbox" value="morning">Morning<br>
<input name="session2" type="checkbox" value="afternoon">Afternoon<br>
<input name="session2" type="checkbox" value="afternoon">Afternoon<br>
<input name="session2" type="checkbox" value="evening">Evening</p>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td><!-- field cannont be left blank --></td>
</tr>
<tr bgcolor="#FFFFFF">
<td align="center"><input name="submit" type="submit" value="submit">
<input name="reset" type="reset" value="reset">
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</td>
<td width="34%"> </td>
</tr>
</table>
</body>
</html>
Really appreciate your time and expertise....
mike