PDA

View Full Version : I have a self grading quiz that won't grade. Help!


TKDPrincess
11-14-2005, 05:29 PM
Hey all!

I am trying to create a quiz that grades itself. So far, I can't get the grading part to work. The code is:

==================
<HTML>
<HEAD>
<SCRIPT language="javascript" type="text/javascript">
var platform = "document.edu.platform.value"
</SCRIPT>
<SCRIPT language="javascript" type="text/javascript">
function checkEdu()
{
if (platform == "")
{
alert("Don't you think students should use some form of computer?")
}
else if (platform.indexOf("Win") == 0)
{
alert("Do you really want your students using that unfriendly a machine?")
}
else if (platform == "Ap")
{
alert("That's a little old, isn't it?")
}
else if (platform == "Unix")
{
alert("Aren't students overpowered by Unix?")
}
else if (platform == "Mac")
{
alert("We agree on that")
}
else
{
alert("Has anyone ever heard of " + platform + "?")
}
}
</SCRIPT>
<TITLE> Quiz </TITLE>
</HEAD>

<BODY bgcolor="CC99FF" text="black">

<H1 align="CENTER"> Quiz </H1>
<HR align="CENTER" width="60%">

<FORM name="edu">
<CENTER>
The best computer platform for education is? <BR>
<INPUT type="RADIO" name="platform" value="Ap">Apple II <BR>
<INPUT type="RADIO" name="platform" value="Mac">Macintosh <BR>
<INPUT type="RADIO" name="platform" value="Unix">Unix with X-Windows<BR>
<INPUT type="RADIO" name="platform" value="Win 95">Windows'95<BR>
<INPUT type="RADIO" name="platform" value="Win 3.1">Windows 3.1<BR>
<INPUT type="RADIO" name="platform" value="Win NT">Windows NT<BR>
<INPUT type="BUTTON" name="check" value="Check" onClick="return checkEdu(platform)">
</CENTER>
</FORM>

</BODY>
</HTML>
==================

Any suggestions to make the alert box come up with the response?

Thanks!

scrypter
11-14-2005, 10:39 PM
This javascript works, your function is changed and there is an additional function.

function checkEdu(){
var chk = getCheckedValue(document.forms['edu'].elements['platform']);

if (chk == "")
{
alert("Don't you think students should use some form of computer?")
}
else if (chk.indexOf("Win") == 0)
{
alert("Do you really want your students using that unfriendly a machine?")
}
else if (chk == "Ap")
{
alert("That's a little old, isn't it?")
}
else if (chk == "Unix")
{
alert("Aren't students overpowered by Unix?")
}
else if (chk == "Mac")
{
alert("We agree on that")
}
else
{
alert("Has anyone ever heard of " + chk + "?")
}
}
// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
if(!radioObj)
return "";
var radioLength = radioObj.length;
if(radioLength == undefined)
if(radioObj.checked)
return radioObj.value;
else
return "";
for(var i = 0; i < radioLength; i++) {
if(radioObj[i].checked) {
return radioObj[i].value;
}
}
return "";
}

HTH
Paul

TKDPrincess
11-14-2005, 10:56 PM
Ok ~ Thanks so much!