...

View Full Version : Another Confused Newbie



ziggah
12-05-2006, 04:53 AM
Hey guys, I am new to javascript and I thought I had a small feel for the language.. I even thought I wrote something that performed a function. www.3rdoct.org/zig/quiz.html is my little quiz template.. now it seems to work fine in IE but in netscape and Firefox some people report it just endlessly loading at the result page or just not loading at all to begin with.. any ideas?

-Ziggah



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
a = 0
b = 0
c = 0
d = 0
e = 0
f = 0
g = 0
function zig()
{
if (document.getElementById("answer1").checked==true)
{
e=e+10
}
else if (document.getElementById("answer1").checked==false)
{
}
if (document.getElementById("answer2").checked==true)
{
e=e+5
}
else if (document.getElementById("answer2").checked==false)
{
}
if (document.getElementById("answer3").checked==true)
{
a=a+10
}
else if (document.getElementById("answer3").checked==false)
{
}
if (document.getElementById("answer4").checked==true)
{
e=e+20
}
else if (document.getElementById("answer4").checked==false)
{
}
if (document.getElementById("answer5").checked==true)
{
e=e+5
}
else if (document.getElementById("answer5").checked==false)
{
}
if (document.getElementById("answer6").checked==true)
{
e=e+10
}
else if (document.getElementById("answer6").checked==false)
{
}
if (document.getElementById("answer7").checked==true)
{
e=e+20
}
else if (document.getElementById("answer7").checked==false)
{
}
if (document.getElementById("answer8").checked==true)
{
a=a+10
}
else if (document.getElementById("answer8").checked==false)
{
}
if (a==0 && e==0)
{
document.write("e:"+e + "<br/> " + "a:"+a+"<br/>" + "You did not select anything.."+ "<br>")
}
else if (a>0 || e>0)
{
document.write("e:"+e + "<br/> " + "a:"+a+"<br/>" + "Explanation: With this code I get to define how each of my variables are effected by selected answers, thus allowing me to later effect the test results, in this case e will equal ineptitude while a will equal aptitude. Or Something.")
}
}
</script>
</head>
<body>
<script type="text/javascript">

</script>
<form action="">
This is a sample quiz I guess. How many licks does it take to get to the center of a tootsie pop?
<br />
<input type="radio" name="question1" id="answer1"/>
ahh one...
<br />
<input type="radio" name="question1" id="answer2"/>
ahh two...
<br />
<input type="radio" name="question1" id="answer3"/>
ahh three...
<br />
<input type="radio" name="question1" id="answer4"/>
can't tell :(
</form>
<form action="">
<br />
This is sample question two.. I suppose. What color is the sky?
<br />
<input type="radio" name="question2" id="answer5"/>
Whats a sky?
<br />
<input type="radio" name="question2" id="answer6"/>
Huh?
<br />
<input type="radio" name="question2" id="answer7"/>
(drooling)
<br />
<input type="radio" name="question2" id="answer8"/>
Blue at day and black at night
<br />
<br />
<input type="submit" name="submit" id="submit" value="Complete Test" onclick="zig()" />
-Zig
</form>
</body>
</html>

coothead
12-05-2006, 10:56 AM
Hi there ziggah,

you need to use document.close()...


document.write("e:"+e + "<br/> " + "a:"+a+"<br/>" + "You did not select anything.."+ "<br>");
document.close();
}
else if (a>0 || e>0)
{
document.write("e:"+e + "<br/> " + "a:"+a+"<br/>" + "Explanation: With this code I get to define how each of my variables are effected by selected answers, thus allowing me to later effect the test results, in this case e will equal ineptitude while a will equal aptitude. Or Something.")
document.close();

Of course, having said that, you should not be using document.write() in the first place. :eek:

Source:-

http://www.w3.org/TR/2004/WD-WCAG20-SCRIPT-TECHS-20041119/#doc-write
coothead

ziggah
12-05-2006, 06:38 PM
blast! *sheds a tear for document.write()* rest in peace old friend.

coothead
12-05-2006, 06:52 PM
Hi there ziggah,

once you finally bury it, you will not miss it at all. :D

coothead



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum