...

View Full Version : Fill in the blank quiz for website



jv00123
12-15-2002, 01:41 AM
Hi, I need to make a quiz with fill in's rather than multiple choice answers. I saw a nice one that would work at http://highered.mcgraw-hill.com/sites/007241409x/student_view0/chapter10/fill_in_the_blanks.html

but i dont know how that works. So, any help or scripts would be greatly appreciated......its gonna be 26 questions

chrismiceli
12-15-2002, 02:16 AM
that is using javascript. the script would be quite long, but for like 2 questions it would look something like this


<script type="text/javascript">
function valid() {
cor = "0"
incor = "0"
test0 = document.myform.elements[0].value;
test1 = document.myform.elements[1].value;
if (test0.toLowerCase() == "codingforums.com") {
++cor; }
else ++incor
if (test1.toLowerCase() == "chrismiceli") {
++cor; }
else ++incor
alert("you got " + cor + " right\n And you got " + incor + " wrong. You got " + cor/2 * 100 + "% correct!");
}
</script>
<body>
<form name="myform">
1. what is the name of this site?
<input type="text" name="q1">
2.what is my name?
<input type="text/javascript">
<br>
<input type="button" onClick="valid()" value="check answers">

jv00123
12-15-2002, 02:55 AM
Okay thanks, i got that to work really well for what i need.

But is there any way to make the results open in new page and display the results and giving the answers and what they answered? Thanks

chrismiceli
12-15-2002, 04:33 AM
sure you can.


<script type="text/javascript">
function valid() {
cor = "0"
incor = "0"
test0 = document.myform.elements[0].value;
test1 = document.myform.elements[1].value;
if (test0.toLowerCase() == "codingforums.com") {
++cor; }
else ++incor
if (test1.toLowerCase() == "chrismiceli") {
++cor; {
else ++incor
document.cookie = escape(test0 + ";" + test1 + ";" + cor + ";" + incor)
}
</script>
<body>
<form name="myform">
1. what is the name of this site?
<input type="text" name="q1">
2.what is my name?
<input type="text/javascript">
<br>
<input type="button" onClick="valid()" value="check answers">

and on the other page


<script type="text/javascript">
cook = unescape(document.cookie)
vals = cook.split(";")
document.getElementById("spanname").innerHtml = "You answered " + vals[0] + " for number 1.<br>You answered " + vals[1] + " for number 2.<br>You got " + vals[2] + " correct and " + incor + " incorrect.<br>You got " + cor/2 * 100 + "% correct.");
</script>
<span id="spanname"></span>

jv00123
12-15-2002, 05:00 AM
what would i have to name the page with the results

jv00123
12-15-2002, 05:35 AM
when the check answers button is clicked, nothing happens, so would this be because of the answer page not being named correctly or something else(i made the quiz page quiz.htm, and the answer page results.htm)
Thanks

chrismiceli
12-15-2002, 06:19 AM
syntax erros, here is a revised one
the quiz page.


<html>
<head>
<title>test</title>
<script type="text/javascript">
function valid() {
cor = "0"
incor = "0"
test0 = document.myform.elements[0].value;
test1 = document.myform.elements[1].value;
if (test0.toLowerCase() == "codingforums.com") {
++cor; }
else {
++incor }
if (test1.toLowerCase() == "chrismiceli") {
++cor; }
else {
++incor }
document.cookie = escape(test0 + ";" + test1 + ";" + cor + ";" + incor)
document.location.href = "results.html" //the results page
}
</script>
<body>
<form name="myform">
1. what is the name of this site?
<input type="text" name="q1">
2.what is my name?
<input type="text/javascript">
<br>
<input type="button" onClick="valid()" value="check answers">
</form>
</body>
</html>

the results page


<html>
<head>
<title>test
</title>
<script type="text/javascript">
function tst() {
cook = unescape(document.cookie)
vals = cook.split(";")
document.write("You answered " + vals[0] + " for number 1.<br>You answered " + vals[1] + " for number 2.<br>You got " + vals[2] + " correct and " + vals[3] + "
incorrect.<br>You got " + vals[2]/2 * 100 + "% correct.");
}
</script>
</head>
<body onLoad="tst()">
<span id="spanname"></span>
</body>
</html>

jv00123
12-15-2002, 07:09 AM
ok thats working

sorry to be a pain, but
1. how do i make the results page's , answers given, appear bold
2. tell which numbers were missed.
3. incorporate the total # correct into something appearing specifically for that amount (i.e. picture after the rest of all the results)

once again, sorry for asking you all these questions.

chrismiceli
12-15-2002, 07:15 AM
the bold would be like this


document.write("You answered <b>" + vals[0] + "</b> for number 1.<br>You answered <b>" + vals[1] + "</b> for number 2.<br>You got <b>" + vals[2] + "</b> correct and <b>" + vals[3] + "
</b>incorrect.<br>You got<b> " + vals[2]/2 * 100 + "%</b> correct.");
}
}

and the rest would just take a lot more programming. you might want to try learning javascript sometime, it is a great language.

jv00123
12-15-2002, 04:06 PM
ok, thanks for all the help

tommysphone
12-16-2002, 08:56 AM
Put the validation in a seperate js file so the answers cannot be easliy found by viewing source :)

jv00123
12-16-2002, 11:27 PM
can you hide the answers if you are using an array, if so, how?

chrismiceli
12-17-2002, 03:50 AM
if you put all your javascript in a file called whatever.js you can call it in your website like so.
<script type="text/javascript" src="whatever.js"></script>
that makes it "harder" to see the source, no where near full proof. but be sure to not include the <script> tags in the js file.

jv00123
12-17-2002, 04:00 AM
ok, thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum