Why won't cookie value show up?

Discussion in 'Javascript' started by Display Name, Dec 9, 2003.

  1. Display Name

    Display Name Guest

    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<=totalquestions;q++){
    var thequestion=eval("document.myquiz.question"+q)
    for (c=0;c<thequestion.length;c++){
    if (thequestion[c].checked==true)
    actualchoices[q]=thequestion[c].value
    }

    if (actualchoices[q]!=correctchoices[q]){ //process an incorrect choice
    if (incorrect==null)
    incorrect=q
    else
    incorrect+="/"+q
    }
    }

    if (incorrect==null)
    incorrect="a/b"
    document.cookie='q='+incorrect
    if (document.cookie=='')
    alert("Your browser does not accept cookies. Please adjust your browser
    settings.")
    else
    window.location="quiz1_results.htm"
    }


    function showsolution(){
    var win2=window.open("","win2","width=200,height=350, scrollbars")
    win2.focus()
    win2.document.open()
    win2.document.write('<title>Solution</title>')
    win2.document.write('<body bgcolor="#FFFFFF">')
    win2.document.write('<center><h3>Solution to Quiz</h3></center>')
    win2.document.write('<center><font face="Arial">')
    for (i=1;i<=totalquestions;i++){
    for (temp=0;temp<incorrect.length;temp++){
    if (i==incorrect[temp])
    wrong=1
    }
    if (wrong==1){
    win2.document.write("Question
    "+i+"="+correctchoices.fontcolor("red")+"<br>")
    wrong=0
    }
    else
    win2.document.write("Question "+i+"="+correctchoices+"<br>")
    }
    win2.document.write('</center></font>')
    win2.document.write("<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.javascriptkit.com' target='_new'>JavaScript Kit quiz
    script</a></small>")
    win2.document.close()
    }
    *************************************


    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=document.cookie.split(";")
    for (n=0;n<=results.length-1;n++){
    if (results[n].charAt(1)=='q')
    parse=n

    }

    var incorrect=results[parse].split("=")
    incorrect=incorrect[1].split("/")
    if (incorrect[incorrect.length-1]=='b')
    incorrect=""
    document.result[0].value=totalquestions-incorrect.length+" out of
    "+totalquestions
    var numberright=totalquestions-incorrect.length
    document.result[2].value=(totalquestions-incorrect.length)/totalquestions*10
    0+"%"
    for (temp=0;temp<incorrect.length;temp++)
    document.result[1].value+=incorrect[temp]+", "


    </script>

    ***********************************


    From a hyperlinked image within the same search results page........
    <a href="JavaScript:newWindow('tellafriend_quiz1.php')"><img
    src="/images/passitalong_quiz.jpg" border="0"></a>

    ............I have it open a new window for the "Tell a friend" using
    this....
    function newWindow(tellafriend){
    tellafriendwindow = window.open(tellafriend, 'tellwin',
    'width=550,height=350')
    tellafriendwindow.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="javascript">

    var wrong=0
    for (e=0;e<=2;e++)
    document.result[e].value=""

    var results=document.cookie.split(";")
    for (n=0;n<=results.length-1;n++){
    if (results[n].charAt(1)=='q')
    parse=n

    }

    var incorrect=results[parse].split("=")
    incorrect=incorrect[1].split("/")
    if (incorrect[incorrect.length-1]=='b')
    incorrect=""
    document.result[0].value=totalquestions-incorrect.length+" out of
    "+totalquestions
    var numberright=totalquestions-incorrect.length

    But when I'm using this "numberright" variable in an alert to tell me
    whether or not i know what the hell I'm doing ....
    <script language="javascript">alert("You 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
     
    Display Name, Dec 9, 2003
    #1
    1. Advertising

  2. Display Name

    name Guest

    3 lines for a cookie.

    You are not only denying knowledge of fraud,
    but eagerly trying to live of it.


    --



    "Display Name" <> wrote in message
    news:BofBb.377782$...
    > 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<=totalquestions;q++){
    > var thequestion=eval("document.myquiz.question"+q)
    > for (c=0;c<thequestion.length;c++){
    > if (thequestion[c].checked==true)
    > actualchoices[q]=thequestion[c].value
    > }
    >
    > if (actualchoices[q]!=correctchoices[q]){ //process an incorrect choice
    > if (incorrect==null)
    > incorrect=q
    > else
    > incorrect+="/"+q
    > }
    > }
    >
    > if (incorrect==null)
    > incorrect="a/b"
    > document.cookie='q='+incorrect
    > if (document.cookie=='')
    > alert("Your browser does not accept cookies. Please adjust your browser
    > settings.")
    > else
    > window.location="quiz1_results.htm"
    > }
    >
    >
    > function showsolution(){
    > var win2=window.open("","win2","width=200,height=350, scrollbars")
    > win2.focus()
    > win2.document.open()
    > win2.document.write('<title>Solution</title>')
    > win2.document.write('<body bgcolor="#FFFFFF">')
    > win2.document.write('<center><h3>Solution to Quiz</h3></center>')
    > win2.document.write('<center><font face="Arial">')
    > for (i=1;i<=totalquestions;i++){
    > for (temp=0;temp<incorrect.length;temp++){
    > if (i==incorrect[temp])
    > wrong=1
    > }
    > if (wrong==1){
    > win2.document.write("Question
    > "+i+"="+correctchoices.fontcolor("red")+"<br>")
    > wrong=0
    > }
    > else
    > win2.document.write("Question "+i+"="+correctchoices+"<br>")
    > }
    > win2.document.write('</center></font>')
    > win2.document.write("<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.javascriptkit.com' target='_new'>JavaScript Kit quiz
    > script</a></small>")
    > win2.document.close()
    > }
    > *************************************
    >
    >
    > 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=document.cookie.split(";")
    > for (n=0;n<=results.length-1;n++){
    > if (results[n].charAt(1)=='q')
    > parse=n
    >
    > }
    >
    > var incorrect=results[parse].split("=")
    > incorrect=incorrect[1].split("/")
    > if (incorrect[incorrect.length-1]=='b')
    > incorrect=""
    > document.result[0].value=totalquestions-incorrect.length+" out of
    > "+totalquestions
    > var numberright=totalquestions-incorrect.length
    >

    document.result[2].value=(totalquestions-incorrect.length)/totalquestions*10
    > 0+"%"
    > for (temp=0;temp<incorrect.length;temp++)
    > document.result[1].value+=incorrect[temp]+", "
    >
    >
    > </script>
    >
    > ***********************************
    >
    >
    > From a hyperlinked image within the same search results page........
    > <a href="JavaScript:newWindow('tellafriend_quiz1.php')"><img
    > src="/images/passitalong_quiz.jpg" border="0"></a>
    >
    > ...........I have it open a new window for the "Tell a friend" using
    > this....
    > function newWindow(tellafriend){
    > tellafriendwindow = window.open(tellafriend, 'tellwin',
    > 'width=550,height=350')
    > tellafriendwindow.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="javascript">
    >
    > var wrong=0
    > for (e=0;e<=2;e++)
    > document.result[e].value=""
    >
    > var results=document.cookie.split(";")
    > for (n=0;n<=results.length-1;n++){
    > if (results[n].charAt(1)=='q')
    > parse=n
    >
    > }
    >
    > var incorrect=results[parse].split("=")
    > incorrect=incorrect[1].split("/")
    > if (incorrect[incorrect.length-1]=='b')
    > incorrect=""
    > document.result[0].value=totalquestions-incorrect.length+" out of
    > "+totalquestions
    > var numberright=totalquestions-incorrect.length
    >
    > But when I'm using this "numberright" variable in an alert to tell me
    > whether or not i know what the hell I'm doing ....
    > <script language="javascript">alert("You 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
    >
    >
     
    name, Dec 10, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. darrel

    My cookie won't set. Why? :(

    darrel, Sep 15, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    473
    darrel
    Sep 15, 2004
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    984
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,234
    Smokey Grindel
    Dec 2, 2006
  4. Mark Olbert
    Replies:
    7
    Views:
    1,487
    Patrice
    Jan 20, 2010
  5. Richard  Lawrence

    HTTP::Cookie won't store sent cookie

    Richard Lawrence, Mar 17, 2005, in forum: Perl Misc
    Replies:
    4
    Views:
    205
    Richard Lawrence
    Mar 21, 2005
Loading...

Share This Page