SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict ghostme's Avatar
    Join Date
    Feb 2005
    Posts
    371
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    js online quiz solution

    Hello good pple of the forum. I 've made a rather sloppy online quiz with js, but the real issue i 've with this quiz is that when a user answers a question he/she can go back to change that previous answer, now i am looking for a way to get round that i.e when a user answer a question, when he/she tries to go back to the question and change, the script would bring out an alert that the question has been answered.
    This is the original script:
    <html>
    <head>
    <title>quiz</title>
    <script>
    function showscore()
    {
    var sum=0,inc=0;second=0,well=0;

    if(document.form1.msword[0].checked==true)
    {inc=document.form1.msword[0].value;
    sum=++inc;
    }
    if(document.form1.excel[1].checked==true)
    {second=document.form1.msword[1].value;
    well=++second;
    }
    if(well+sum==1){
    alert(well+sum+" point");}
    else{
    alert(well+sum+" points");
    }
    }
    </script>
    </head>
    <body>
    <form name="form1">
    1.what is msword?<br/>
    <input type="radio" name="msword" value=0>a word processor<br/>
    <input type="radio" name="msword" value=0>a graphic
    <input type=”button” onclick=”showscore();” value=”checkscore”>
    </body>
    </html>
    Thank you for taking a look!!!!!!!!!!!!!

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As you might know, web pages are stateless, so they have no memory. That means no page knows about any other page. If the user goes back a page, the page has no idea there are even other pages in existence or that a question had been answered previously. So, you are going to have to use cookies to make information 'persist' in the browser across pages. Any time a page loads, you can check your cookie, and if the cookie contains an answer for a question, you could alert() a message and just disable the input field.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •