473,795 Members | 3,331 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Validate Online Test

2 New Member
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>Registra tion Form</title>
<SCRIPT LANGUAGE="JavaS cript">
<!-- 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(theMessag e);
return false;
}
}
// End -->
</script>
</head>

<body>

<table border="1" width="100%">
<tr>
<td width="33%">&nb sp;</td>
<td width="33%"><fo rm name="form1" action="cgi-bin/sendmail_mike.a sp" onSubmit="retur n validate(this); ">
<table width="300" border="0" cellpadding="0" cellspacing="0" >
<tr>
<td bgcolor="#ccccc c">
<table width="100%" border="0" cellpadding="3" cellspacing="1" >
<tr bgcolor="#FFFFF F">
<td align="center"> Registration Form</td>
</tr>
<tr bgcolor="#FFFFF F">
<td>First Name:<!-- field cannont be left blank --><br>
<input type="Text" name="name" size="20"></td>
</tr>
<tr bgcolor="#FFFFF F">
<td>Last Name:<!-- field cannont be left blank --><br>
<input type="Text" name="name1" size="20">
</td>
</tr>
<tr bgcolor="#FFFFF F">
<td></td>
</tr>
<tr bgcolor="#FFFFF F">
<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="afternoo n">Afternoon<br >
<input name="session1" type="checkbox" value="afternoo n">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="afternoo n">Afternoon<br >
<input name="session2" type="checkbox" value="afternoo n">Afternoon<br >
<input name="session2" type="checkbox" value="evening" >Evening</p>
</td>
</tr>
<tr bgcolor="#FFFFF F">
<td>
</td>
</tr>
<tr bgcolor="#FFFFF F">
<td><!-- field cannont be left blank --></td>
</tr>
<tr bgcolor="#FFFFF F">
<td align="center"> <input name="submit" type="submit" value="submit">
&nbsp;&nbsp;<in put name="reset" type="reset" value="reset">
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>


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

</body>

</html>


Really appreciate your time and expertise....

mike
Aug 7 '07 #1
1 2838
jhardman
3,406 Recognized Expert Specialist
Mike,

Rather than use a submit button, just use a <input type="button" onClick="valida te()"> 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.f orm1.fname.valu e=="")
{
document.all.fo rm1.fname.style .color='red';
var complete = false;
}

if (document.all.f orm1.lname.valu e=="")
{
document.all.fo rm1.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
1641
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
2038
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 ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/) <Id>+1JdgFR4s0SmYUNDRGFzEw==</Id>
0
1319
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 exam could better judge ourselves please do reply me.
3
1641
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 have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE email_add='postmaster@universaltutors.co.uk'' at line 1 can anyone help me with this issue? thanks for your...
1
1263
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
5089
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 must be embedded somewhere in the source code, and I would like to know if anyone knows where to find the correct answer. I would greatly appreciate it!! Thanks!! <!--put the preloads file here as it must load before the website class...
4
68273
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 must be embedded somewhere in the source code, and I would like to know if anyone knows where to find the correct answer. I would greatly appreciate it!! Thanks!!
9
9706
by: preeto50 | last post by:
go to http://www.itworld2.com to take online test of c++...........
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10435
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10213
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9037
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.