473,373 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,373 software developers and data experts.

Validate Online Test

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%">&nbsp;</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">
&nbsp;&nbsp;<input name="reset" type="reset" value="reset">
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>


</td>
<td width="34%">&nbsp;</td>
</tr>
</table>

</body>

</html>


Really appreciate your time and expertise....

mike
Aug 7 '07 #1
1 2814
jhardman
3,406 Expert 2GB
Mike,

Rather than use a submit button, just use a <input type="button" onClick="validate()"> and make a javascript function that checks all the fields. If the fields are left blank, the javascript function should make that input field change colors, otherwise the function should submit the form. I'm not an expert on javascript, but this is pretty easy (and I probably don't have too many errors):[html]
function validate()
{
var complete = true;
if (document.all.form1.fname.value=="")
{
document.all.form1.fname.style.color='red';
var complete = false;
}

if (document.all.form1.lname.value=="")
{
document.all.form1.lname.style.color='red';
var complete = false;
}

/etc

if (complete == true)
{ location.href="/nextPage.asp"
}
else
{
alert("Please make sure all required fields are completed")
}

}[/html]Jared
Aug 7 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: RS | last post by:
Hi, I am looking for some open source online test/exam system using ASP.net and SQL server 2000. Does anyone have any suggestion? Thank you! RS
2
by: id santhosh via .NET 247 | last post by:
(Type your message here) i will have to conduct a online test using timer? how can i implement? please send some codes also..please help.. -------------------------------- From: id santhosh ...
0
by: jack | last post by:
Hi all, Im planning to take dot net certification exam. i want to know whether is there any site which helps you in preparing for exam. like taking line test for 30 mins so that before taking...
3
by: joelt | last post by:
hi i am trying to setup this product with MySQL - 4.1.20. but there seem to be a million and one problems with some of the pages related to mysql: for example see below: SELECTION PROBLEM: You...
1
by: Rama Jayapal | last post by:
can anyone give an idea like how to develop an online quiz how can i enter questions how to match entered answers with the ight answer and get the result
2
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
4
by: emily224 | last post by:
Hello, I have been trying to understand this source code, which I retreived from my online course test. I would like to know how to find the answer for the question on the test. Im sure the answer...
9
by: preeto50 | last post by:
go to http://www.itworld2.com to take online test of c++...........
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.