Navigating Pages and passing values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • valhalen
    New Member
    • Mar 2008
    • 6

    Navigating Pages and passing values

    hi,

    I am creating a quiz application in Javascript where each page has one question. I would like to calculate the score and time taken to answer all questions at the very end - how do I achieve this? Can I pass values (like score for each question and time taken to answer that question) to the next page so that I can total it at the very end?

    OS: Windows

    thank you.
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    hi ...

    of course you can :) some of the possibilities:

    1. use cookies
    2. pass the variables with the url as a querystring
    3. use a frameset with a hidden frame and load your current pages in a visible one

    kind regards

    Comment

    • valhalen
      New Member
      • Mar 2008
      • 6

      #3
      thanks,

      I was trying to pass them via the URL but I can only pass static values
      ex: <input type="button" name="Button1" value="Go to 2nd Page" onclick="locati on.href='2ndpag e.html?attr1=20 &attr2=60'" disabled="disab led">

      whereas I want to pass variables whose values are not predetermined, I have tried something like below but it doesnt work

      <input type="button" name="Button1" value="Go to 2nd Page" onclick="locati on.href='2ndpag e.html?attr1="+ attrval_1+"&att r2="+attrval_2+ "'" disabled="disab led">

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        try the following:

        [CODE=javascript]// function that sets the location
        function set_location(va l1, val2) {
        window.location .href = '2ndpage.html?a ttr1=' + val1 + '&attr2=' + val2;
        }
        [/CODE]
        in your onclick call the function:

        [HTML]onclick="set_lo cation(attrval_ 1, attrval_2);"
        [/HTML]
        kind regards

        Comment

        • FredSovenix
          New Member
          • Mar 2008
          • 10

          #5
          You might want to pass the answers and times through a hidden form field. This would avoid any length restriction on the query string if your quiz is of any size.

          Comment

          • valhalen
            New Member
            • Mar 2008
            • 6

            #6
            thanks guys

            Fred - I will be sending a small set of values, so I am not worried about maxing out the length, but thx anyways.

            Comment

            Working...