Used one of these canned scripts to set up a JS quiz but not before having
used another canned PHP script for "Tell your friend about this Web page!"
sort of thing. Now i've gotta integrate them; client wants the results from
the quiz to go into the email.
The file "quizconfig .js" parses the form-submitted test results & the test
results page (quiz1_results. htm), in turn, shows the score. The JS in the
quizconfig.js appears to set a cookie from which quiz1_results gets the
calculated score. So I pasted all the same JavaScript that appears in the
quiz1_results page into the "Tell your Friend" page in an attempt to be able
to tweak the (PHP-based) email body to contain the variable that holds the
results.
I keep getting "Undefined" for the value of the variable. Can't figure out
what I might be doing wrong.
the source code of "quizconfig .js" is here (between line of asterisks):
*************** *************** ***********
//Enter total number of questions:
var totalquestions= 10
//Enter the solutions corresponding to each question:
var correctchoices= new Array()
correctchoices[1]='b' //question 1 solution
correctchoices[2]='b' //question 2 solution, and so on.
correctchoices[3]='c'
correctchoices[4]='a'
correctchoices[5]='a'
correctchoices[6]='c'
correctchoices[7]='c'
correctchoices[8]='b'
correctchoices[9]='c'
correctchoices[10]='b'
/////Don't edit beyond here//////////////////////////
function gradeit(){
var incorrect=null
for (q=1;q<=totalqu estions;q++){
var thequestion=eva l("document.myq uiz.question"+q )
for (c=0;c<thequest ion.length;c++) {
if (thequestion[c].checked==true)
actualchoices[q]=thequestion[c].value
}
if (actualchoices[q]!=correctchoice s[q]){ //process an incorrect choice
if (incorrect==nul l)
incorrect=q
else
incorrect+="/"+q
}
}
if (incorrect==nul l)
incorrect="a/b"
document.cookie ='q='+incorrect
if (document.cooki e=='')
alert("Your browser does not accept cookies. Please adjust your browser
settings.")
else
window.location ="quiz1_results .htm"
}
function showsolution(){
var win2=window.ope n("","win2","wi dth=200,height= 350, scrollbars")
win2.focus()
win2.document.o pen()
win2.document.w rite('<title>So lution</title>')
win2.document.w rite('<body bgcolor="#FFFFF F">')
win2.document.w rite('<center>< h3>Solution to Quiz</h3></center>')
win2.document.w rite('<center>< font face="Arial">')
for (i=1;i<=totalqu estions;i++){
for (temp=0;temp<in correct.length; temp++){
if (i==incorrect[temp])
wrong=1
}
if (wrong==1){
win2.document.w rite("Question
"+i+"="+correct choices[i].fontcolor("red ")+"<br>")
wrong=0
}
else
win2.document.w rite("Question "+i+"="+correct choices[i]+"<br>")
}
win2.document.w rite('</center></font>')
win2.document.w rite("<h5>Note: The solutions in red are the ones to the
questions you had incorrectly answered.</h5><p align='center'> <small><a
href='http://www.javascriptk it.com' target='_new'>J avaScript Kit quiz
script</a></small>")
win2.document.c lose()
}
*************** *************** *******
The (canned) JS used in the search results page is here (or if you take the
test & get the results page at http://www.smoochya.com/quiz1.html you can
see it):
*************** *************** *********
<script src="quizconfig .js">
</script>
<script>
var wrong=0
for (e=0;e<=2;e++)
document.result[e].value=""
var results=documen t.cookie.split( ";")
for (n=0;n<=results .length-1;n++){
if (results[n].charAt(1)=='q' )
parse=n
}
var incorrect=resul ts[parse].split("=")
incorrect=incor rect[1].split("/")
if (incorrect[incorrect.lengt h-1]=='b')
incorrect=""
document.result[0].value=totalque stions-incorrect.lengt h+" out of
"+totalquestion s
var numberright=tot alquestions-incorrect.lengt h
document.result[2].value=(totalqu estions-incorrect.lengt h)/totalquestions* 10
0+"%"
for (temp=0;temp<in correct.length; temp++)
document.result[1].value+=incorre ct[temp]+", "
</script>
*************** *************** *****
From a hyperlinked image within the same search results page........
<a href="JavaScrip t:newWindow('te llafriend_quiz1 .php')"><img
src="/images/passitalong_qui z.jpg" border="0"></a>
............I have it open a new window for the "Tell a friend" using
this....
function newWindow(tella friend){
tellafriendwind ow = window.open(tel lafriend, 'tellwin',
'width=550,heig ht=350')
tellafriendwind ow.focus()
}
Within the "Tell A Friend" PHP page (http://, I have the same JS as what's
in the search results:
<script src="quizconfig .js">
</script>
<script language="javas cript">
var wrong=0
for (e=0;e<=2;e++)
document.result[e].value=""
var results=documen t.cookie.split( ";")
for (n=0;n<=results .length-1;n++){
if (results[n].charAt(1)=='q' )
parse=n
}
var incorrect=resul ts[parse].split("=")
incorrect=incor rect[1].split("/")
if (incorrect[incorrect.lengt h-1]=='b')
incorrect=""
document.result[0].value=totalque stions-incorrect.lengt h+" out of
"+totalquestion s
var numberright=tot alquestions-incorrect.lengt h
But when I'm using this "numberrigh t" variable in an alert to tell me
whether or not i know what the hell I'm doing ....
<script language="javas cript">alert("Y ou got " + numberright + "
right!")</script>
.......it doesn't work.
the pages involved can be seen at http://www.smoochya.com/quiz1.html I feel
like I'm almost there but I can't seem to get the value of the number right
to persist through to the tell-a-friend page.
Any suggestions?
Thanks in advance!
Matt
used another canned PHP script for "Tell your friend about this Web page!"
sort of thing. Now i've gotta integrate them; client wants the results from
the quiz to go into the email.
The file "quizconfig .js" parses the form-submitted test results & the test
results page (quiz1_results. htm), in turn, shows the score. The JS in the
quizconfig.js appears to set a cookie from which quiz1_results gets the
calculated score. So I pasted all the same JavaScript that appears in the
quiz1_results page into the "Tell your Friend" page in an attempt to be able
to tweak the (PHP-based) email body to contain the variable that holds the
results.
I keep getting "Undefined" for the value of the variable. Can't figure out
what I might be doing wrong.
the source code of "quizconfig .js" is here (between line of asterisks):
*************** *************** ***********
//Enter total number of questions:
var totalquestions= 10
//Enter the solutions corresponding to each question:
var correctchoices= new Array()
correctchoices[1]='b' //question 1 solution
correctchoices[2]='b' //question 2 solution, and so on.
correctchoices[3]='c'
correctchoices[4]='a'
correctchoices[5]='a'
correctchoices[6]='c'
correctchoices[7]='c'
correctchoices[8]='b'
correctchoices[9]='c'
correctchoices[10]='b'
/////Don't edit beyond here//////////////////////////
function gradeit(){
var incorrect=null
for (q=1;q<=totalqu estions;q++){
var thequestion=eva l("document.myq uiz.question"+q )
for (c=0;c<thequest ion.length;c++) {
if (thequestion[c].checked==true)
actualchoices[q]=thequestion[c].value
}
if (actualchoices[q]!=correctchoice s[q]){ //process an incorrect choice
if (incorrect==nul l)
incorrect=q
else
incorrect+="/"+q
}
}
if (incorrect==nul l)
incorrect="a/b"
document.cookie ='q='+incorrect
if (document.cooki e=='')
alert("Your browser does not accept cookies. Please adjust your browser
settings.")
else
window.location ="quiz1_results .htm"
}
function showsolution(){
var win2=window.ope n("","win2","wi dth=200,height= 350, scrollbars")
win2.focus()
win2.document.o pen()
win2.document.w rite('<title>So lution</title>')
win2.document.w rite('<body bgcolor="#FFFFF F">')
win2.document.w rite('<center>< h3>Solution to Quiz</h3></center>')
win2.document.w rite('<center>< font face="Arial">')
for (i=1;i<=totalqu estions;i++){
for (temp=0;temp<in correct.length; temp++){
if (i==incorrect[temp])
wrong=1
}
if (wrong==1){
win2.document.w rite("Question
"+i+"="+correct choices[i].fontcolor("red ")+"<br>")
wrong=0
}
else
win2.document.w rite("Question "+i+"="+correct choices[i]+"<br>")
}
win2.document.w rite('</center></font>')
win2.document.w rite("<h5>Note: The solutions in red are the ones to the
questions you had incorrectly answered.</h5><p align='center'> <small><a
href='http://www.javascriptk it.com' target='_new'>J avaScript Kit quiz
script</a></small>")
win2.document.c lose()
}
*************** *************** *******
The (canned) JS used in the search results page is here (or if you take the
test & get the results page at http://www.smoochya.com/quiz1.html you can
see it):
*************** *************** *********
<script src="quizconfig .js">
</script>
<script>
var wrong=0
for (e=0;e<=2;e++)
document.result[e].value=""
var results=documen t.cookie.split( ";")
for (n=0;n<=results .length-1;n++){
if (results[n].charAt(1)=='q' )
parse=n
}
var incorrect=resul ts[parse].split("=")
incorrect=incor rect[1].split("/")
if (incorrect[incorrect.lengt h-1]=='b')
incorrect=""
document.result[0].value=totalque stions-incorrect.lengt h+" out of
"+totalquestion s
var numberright=tot alquestions-incorrect.lengt h
document.result[2].value=(totalqu estions-incorrect.lengt h)/totalquestions* 10
0+"%"
for (temp=0;temp<in correct.length; temp++)
document.result[1].value+=incorre ct[temp]+", "
</script>
*************** *************** *****
From a hyperlinked image within the same search results page........
<a href="JavaScrip t:newWindow('te llafriend_quiz1 .php')"><img
src="/images/passitalong_qui z.jpg" border="0"></a>
............I have it open a new window for the "Tell a friend" using
this....
function newWindow(tella friend){
tellafriendwind ow = window.open(tel lafriend, 'tellwin',
'width=550,heig ht=350')
tellafriendwind ow.focus()
}
Within the "Tell A Friend" PHP page (http://, I have the same JS as what's
in the search results:
<script src="quizconfig .js">
</script>
<script language="javas cript">
var wrong=0
for (e=0;e<=2;e++)
document.result[e].value=""
var results=documen t.cookie.split( ";")
for (n=0;n<=results .length-1;n++){
if (results[n].charAt(1)=='q' )
parse=n
}
var incorrect=resul ts[parse].split("=")
incorrect=incor rect[1].split("/")
if (incorrect[incorrect.lengt h-1]=='b')
incorrect=""
document.result[0].value=totalque stions-incorrect.lengt h+" out of
"+totalquestion s
var numberright=tot alquestions-incorrect.lengt h
But when I'm using this "numberrigh t" variable in an alert to tell me
whether or not i know what the hell I'm doing ....
<script language="javas cript">alert("Y ou got " + numberright + "
right!")</script>
.......it doesn't work.
the pages involved can be seen at http://www.smoochya.com/quiz1.html I feel
like I'm almost there but I can't seem to get the value of the number right
to persist through to the tell-a-friend page.
Any suggestions?
Thanks in advance!
Matt
Comment