Click to See Complete Forum and Search --> : radio button form


Rabbit Man
03-26-2003, 07:59 PM
I am trying to write a test form for my site, and I can't get the script to work. I am just starting with JavaScript, and I am probably making a lot of mistakes, so please help. For some reason, the alert boxes won't appear when the form is submitted. The entire HTML code with script is as follows:

<html>
<head>
<title>The Page of the Web Design Quiz</title>
<link rel="STYLESHEET" type="text/css" href="../radioactive/rrrcss.css">

<script language="JavaScript">

function ansAdd() {
var a = 0; {
if (form.font.value = "true") {
a++
} if (form.ftp.value = "true") {
a++
} if (form.acro.value = "true") {
a++
} if (a = 3) {
alert("You got a perfect score!")
} else {
alert("Not quite perfect.")
}
}
}

</script>

</head>
<body bgcolor=#000000><font color=#00CCFF>
<br><br><br><br>
<form>
<table border=10 bordercolor=#000000 width=100%>
<tr>
<td width=50% colspan=2>
<font face="Courier New">
<b>1. What font is this question written in?</b></font>
</td>
<td width=50% colspan=2>
<b>2. What does FTP stand for?</b>
</td>
</tr>
<tr>
<td width=25%>
<font size=-1>
Courier<br>
Century Gothic<br>
Courier New<br>
Fixedsys
</font>
</td>
<td width=25%>
<input type="radio" name="font" value="false"><br>
<input type="radio" name="font" value="true"><br>
<input type="radio" name="font" value="false"><br>
<input type="radio" name="font" value="false">
</td>
<td width=25%>
<font size=-1>
Fat Tuesday Party<br>
Fan Tan Pan<br>
Folder Test Procedure<br>
File Transfer Protocol
</font>
</td>
<td width=25%>
<input type="radio" name="ftp" value="false"><br>
<input type="radio" name="ftp" value="false"><br>
<input type="radio" name="ftp" value="false"><br>
<input type="radio" name="ftp" value="true">
</td>
</tr>
<tr>
<td width=50% colspan=2>
<b>Which of these is not an <u>internet</u> acronym?</b>
</td>

</tr>
<tr>
<td width=25%>
YMCA<br>
HTTP<br>
URL<br>
CGI
</td>
<td width=25%>
<input type="radio" name="acro" value="true"><br>
<input type="radio" name="acro" value="false"><br>
<input type="radio" name="acro" value="false"><br>
<input type="radio" name="acro" value="false">
</td>

</tr>
</table>
<input type="submit" name="submit" value="SUBMIT THE TEST" onClick="ansAdd()">
</form>

Rabbit Man
03-27-2003, 05:42 AM
I am using IE, and error messages are on. I was getting syntax errors, but I fixed those problems, and they don't appear anymore. I am new to JavaScript, and I am not sure what logic errors I am making. This is my first script, so I have no idea what to do.

Rabbit Man
03-27-2003, 10:20 AM
Okay, here's a link. I was running the code on my computer in IE, on the hard drive. The code at the link is slightly different. Here it is:

the script is here (http://www.elementcontrollers.com/~nesb/radioactive/wdtest.html)

Rabbit Man
03-27-2003, 07:50 PM
Thank you for your help. There is still one problem, though. When the alert box appears, it always says that all 3 answers are correct, even if no buttons are checked. I don't want to be a bother, but this is my first script, and once I learn how to do it right, I'll pick the rest up quick. Thanks. The link to the live code still works, and it has been updated with the corrections.