www.webdeveloper.com
Results 1 to 9 of 9

Thread: Help with transferring data to another page

  1. #1
    Join Date
    May 2009
    Location
    Christchurch, New Zealand
    Posts
    6

    Red face Help with transferring data to another page

    Hi, I have just started learning javascript and would really like some help.

    I am making an online Reading test that is 2 pages long. I want to transfer the answers from the first page to the next page. So that when the user hits submit on the second page all the results are collated.

    Can anyone give me the code I need to do that?

    Thank you!

  2. #2
    Join Date
    May 2009
    Location
    Christchurch, New Zealand
    Posts
    6
    This is the coding I have so far:

    PAGE 1
    <html>
    <body>
    <head>
    <title></title>
    <script type="text/javascript">

    //Reading efficiency score
    var readingEff = 0;
    //Comprehension score
    var comprehension = 0;
    //Vocab score
    var vocab = 0;
    //Reading range score
    var readingRange = 0;
    //Check answers of form
    function validate() {

    //Check question 1
    if (document.part1.question1c.checked) {
    //Add a point to reading efficiency
    readingEff++;
    //test that it worked
    //alert(readingEff.toString());
    }
    //Check question 2
    if (document.part1.question2b.checked) {
    //Add a point to reading efficiency
    readingEff++;
    }
    //Check question 3
    if (document.part1.question3d.checked) {
    //Add a point to reading efficiency
    readingEff++;
    }
    //Check question 4
    if (document.part1.question4b.checked) {
    //Add a point to comprehension
    comprehension++;
    }
    //Check question 5
    if (document.part1.question5a.checked) {
    //Add a point to vocab
    vocab++;
    }
    //Check question 6
    if (document.part1.question6b.checked) {
    //Add a point to vocab
    vocab++;
    }
    //Check question 7
    if (document.part1.question7a.checked) {
    //Add a point to comprehension
    comprehension++;
    }
    //Check question 8
    if (document.part1.question8a.checked) {
    //Add a point to vocab
    vocab++;
    }
    //Check question 9
    if (document.part1.question9b.checked) {
    //Add a point to comprehension & reading range
    comprehension++; readingRange++;
    }
    //Check question 10
    if (document.part1.question10b.checked) {
    //Add a point to comprehension
    comprehension++;
    }
    //Check question 11
    if (document.part1.question11c.checked) {
    //Add a point to comprehension
    comprehension++;
    }
    //Check question 12
    if (document.part1.question12c.checked) {
    //Add a point to comprehension to reading range
    comprehension++; readingRange++;
    }
    //Load next page
    window.location.href = "ReadingTestPart2.html?ReadingEff=" + readingEff.toString() + "&comprehension=" + comprehension.toString() + "&vocab=" + vocab.toString() + "&readingRange=" + readingRange.toString();
    }
    </script>
    </head>
    <h1 style="font-family:arial;color:rgb(174, 16, 61);">King's Reading Assessment</h1>
    <p style="font-family:arial">Time allowed: 25 minutes<br />
    Number of Questions: 20</p><br />
    <p style="font-family:arial"><b>Part One</b></p>
    <p style="font-family:arial">Read the information below and answer questions 1 - 12. You have 10 minutes to complete Part 1.</p>
    <form id="part1" style="font-family:arial" action="ReadingTestPart2.html">
    <br />
    <p><b>1. What kind of course is described in the passage?</b></p>
    <input type="radio" name="question1a" value="study courses" /> study courses
    <br />
    <input type="radio" name="question1b" value="hand-writing courses" /> hand-writing courses
    <br />
    <input type="radio" name="question1c" value="typing courses" /> typing courses
    <br />
    <input type="radio" name="question1d" value="note-taking courses" /> note-taking courses
    <br />
    <p><b>2. Who offers the course?</b></p>
    <input type="radio" name="question 2a" value="a high school" /> a high school
    <br />
    <input type="radio" name="question 2b" value="the university" /> the university
    <br />
    <input type="radio" name="question 2c" value="a computer training company" /> a computer training company
    <br />
    <input type="radio" name="question 2d" value="a community college" /> a community college
    <br />
    <p><b>3. What time do the courses start in the morning?</b></p>
    <input type="radio" name="question 3a" value="9.00pm" /> 9.00pm
    <br />
    <input type="radio" name="question 3b" value="10.00am" /> 10.00am
    <br />
    <input type="radio" name="question 3c" value="anytime" /> anytime
    <br />
    <input type="radio" name="question 3d" value="9.00am" /> 9.00am
    <br />
    <p><b>4. The typing course allows students to</b></p>
    <input type="radio" name="question 4a" value="work in groups" /> work in groups
    <br />
    <input type="radio" name="question 4b" value="work as fast or slow as they choose" /> work as fast or slow as they choose
    <br />
    <input type="radio" name="question 4c" value="start at anytime during the academic year" /> start at anytime during the academic year
    <br />
    <input type="radio" name="question 4d" value="work through the programme in a specified order" /> work through the programme in a specified order
    <br />
    <p><b>5. How many times during the year does the course run?</b></p>
    <input type="radio" name="question 5a" value="once a year" /> once a year
    <br />
    <input type="radio" name="question 5b" value="every month of the year" /> every month of the year
    <br />
    <input type="radio" name="question 5c" value="twice" /> twice
    <br />
    <input type="radio" name="question 5d" value="the start of every term" /> the start of every term
    <br />
    <p><b>6. The last part of the programme teaches…</b></p>
    <input type="radio" name="question 6a" value="speed and accuracy" /> speed and accuracy
    <br />
    <input type="radio" name="question 6b" value="the numeric keyboard" /> the numeric keyboard
    <br />
    <input type="radio" name="question 6c" value="the internet" /> the internet
    <br />
    <input type="radio" name="question 6d" value="the alphabet" /> the alphabet
    <br />
    <p><b>7. The courses are taught every morning during orientation week.</b></p>
    <input type="radio" name="question 7a" value="True" /> True
    <br />
    <input type="radio" name="question 7b" value="False" /> False
    <br />
    <input type="radio" name="question 7c" value="Not Given" /> Not Given
    <br />
    <p><b>8. For optimum speed all ten fingers should be used.</b></p>
    <input type="radio" name="question 8a" value="True" /> True
    <br />
    <input type="radio" name="question 8b" value="False" /> False
    <br />
    <input type="radio" name="question 8c" value="Not Given" /> Not Given
    <br />
    <p><b>9. Students must take their own computer.</b></p>
    <input type="radio" name="question 9a" value="True" /> True
    <br />
    <input type="radio" name="question 9b" value="False" /> False
    <br />
    <input type="radio" name="question 9c" value="Not Given" /> Not Given
    <br />
    <p><b>10. There are no costs involved in taking this course.</b></p>
    <input type="radio" name="question 10a" value="True" /> True
    <br />
    <input type="radio" name="question 10b" value="False" /> False
    <br />
    <input type="radio" name="question 10c" value="Not Given" /> Not Given
    <br />
    <p><b>11. Touch typing is a very important skill for university students.</b></p>
    <input type="radio" name="question 11a" value="True" /> True
    <br />
    <input type="radio" name="question 11b" value="False" /> False
    <br />
    <input type="radio" name="question 11c" value="Not Given" /> Not Given
    <br />
    <p><b>12. The teacher has a degree in computer science.</b></p>
    <input type="radio" name="question 12a" value="True" /> True
    <br />
    <input type="radio" name="question 12b" value="False" /> False
    <br />
    <input type="radio" name="question 12c" value="Not Given" /> Not Given
    <br />
    <br />
    <a href="javascript: validate()">Submit</a>
    </form>


    </body>
    </html>

  3. #3
    Join Date
    May 2009
    Location
    Christchurch, New Zealand
    Posts
    6
    PAGE 2
    <html>
    <head>
    <title></title>
    <script language="javascript" type="text/javascript">
    //Reading efficiency score
    var readingEff = 0;
    //Comprehension score
    var comprehension = 0;
    //Vocab score
    var vocab = 0;
    //Reading range score
    var readingRange = 0;

    function loadvars() {

    //Get the values
    var x = location.search.substr(1).split("&");
    //Reading efficiency score
    var readingEff = x[0].split("=")[1];
    //Comprehension score
    var comprehension = x[1].split("=")[1];
    //Vocab score
    var vocab = x[2].split("=")[1];
    //Reading range score
    var readingRange = x[3].split("=")[1];

    alert(readingEff.toString());
    }

    function validate() {
    //Check question 13
    if (1 == 1) {
    //Add point to comprehension, vocab, reading range
    comprehension++;vocab++;readingRange++;
    }
    //Check question 14
    //Add point to reading efficiency, comprehension, vocab, reading range
    readingEff++;comprehension++;vocab++;readingRange++;
    //Check question 15
    //Add point to reading efficiency, comprehension, vocab, reading range
    readingEff++; comprehension++; vocab++; readingRange++;
    //Check question 16
    //Add point to reading efficiency, comprehension, vocab, reading range
    readingEff++; comprehension++; vocab++; readingRange++;
    //Check question 17
    //Add point to reading efficiency, comprehension, vocab, reading range
    readingEff++; comprehension++; vocab++; readingRange++;
    //Check question 18
    //Add point to reading efficiency, comprehension, vocab, reading range
    readingEff++; comprehension++; vocab++; readingRange++;
    //Check question 19
    //Add point to reading efficiency, comprehension, vocab, reading range
    readingEff++; comprehension++; vocab++; readingRange++;
    //Check question 20
    //Add point to reading efficiency, comprehension, vocab, reading range
    readingEff++; comprehension++; vocab++; readingRange++;
    //Provide results

    }
    </script>
    </head>
    <body onload="loadvars">
    <h1 style="font-family:arial;color:rgb(174, 16, 61);">King's Reading Assessment</h1>
    <p style="font-family:arial"><b>Part Two</b></p>
    <p style="font-family:arial"><b>Read the information below and answer Questions 13 – 20. You have 15 minutes to complete Part 2.</b></p>
    <p style="font-family:arial"><b>Questions 13 – 19</b></p>
    <p style="font-family:arial">Complete each of the statements with the best ending (A – G) from the box on the right. Write your answers in the spaces provided on the Answer Sheet.</p>
    <table border="1">
    <tr><td>
    <table cellpadding="3" style="font-family:arial">
    <tr>
    <td>A</td>
    <td>
    we must use our brains if we wish to maintain our memories and brain function.</td>
    </tr>
    <tr>
    <td>B</td>
    <td>they improve their chances of maintaining their memory and mental functions.</td>
    </tr>
    <tr>
    <td>C</td>
    <td>our reactions become slower</td>
    </tr>
    <tr>
    <td>D</td>
    <td>using their brain and stretching their mental faculties</td>
    </tr>
    <tr>
    <td>E
    </td><td>it becomes harder to learn new skills</td>
    </tr>
    <tr>
    <td>F</td>
    <td>because the temporal lobes are particularly vulnerable to the effects of ageing.</td>
    </tr>
    <tr>
    <td>G</td>
    <td>brain cells</td>
    </tr>
    </table>
    </td></tr></table>
    <br />
    <form style="font-family:arial" id="answers" action="ReadingTestPart2.html">
    <table cellpadding="3"><tr><td>
    13. Neurons can be best described as....
    </td><td>
    <input type="text" maxlength="1" size="1" name="13. Neurons can be best described as...." />
    </td></tr>
    <tr><td>
    14. Research indicates that...
    </td><td>
    <input type="text" maxlength="1" size="1" name="14. Research indicates that..." />
    </td></tr>
    <tr><td>
    15. As the temporal lobes of the brain are affected by ageing...
    </td><td>
    <input type="text" maxlength="1" size="1" name="15. As the temporal lobes of the brain are affected by ageing..." />
    </td></tr>
    <tr><td>
    16. A person can keep their brain active by...
    </td><td>
    <input type="text" maxlength="1" size="1" name="16. A person can keep their brain active by..." />
    </td></tr>
    <tr><td>
    17. If a person’s brain is kept active...
    </td><td>
    <input type="text" maxlength="1" size="1" name="17. If a person’s brain is kept active..." />
    </td></tr>
    <tr><td>
    18. We take longer to learn a new language as we get older....
    </td><td>
    <input type="text" maxlength="1" size="1" name="18. We take longer to learn a new language as we get older.... " />
    </td></tr>
    <tr><td>
    19. As the neurons in the brain become less efficient...
    </td><td>
    <input type="text" maxlength="1" size="1" name="19. As the neurons in the brain become less efficient..." />
    </td></tr>
    </table>
    </form>
    <p style="font-family:arial"><b>Question 20</b></p>
    <p style="font-family:arial">Which THREE of the following are given in the text? Please select from the options below.</p>
    <form action="" style="font-family:arial">
    <table cellpadding="3">
    <tr><td>
    A description of the ways in which mental function changes as we get older
    </td><td>
    <input type="checkbox" name="a description of the ways in which mental function changes as we get older" value="a description of the ways in which mental function changes as we get older" />
    </td></tr>
    <tr><td>
    An explanation of how mental decline can be limited
    </td><td>
    <input type="checkbox" name="an explanation of how mental decline can be limited" value="an explanation of how mental decline can be limited" />
    </td></tr>
    <tr><td>
    An explanation for why people go bald and grey with age
    </td><td>
    <input type="checkbox" name="an explanation for why people go bald and grey with age" value="an explanation for why people go bald and grey with age" />
    </td></tr>
    <tr><td>
    A description of various parts of the brain and their function
    </td><td>
    <input type="checkbox" name="a description of various parts of the brain and their function" value="a description of various parts of the brain and their function" />
    </td></tr>
    <tr><td>
    A detailed report showing results of several research projects
    </td><td>
    <input type="checkbox" name="a detailed report showing results of several research projects" value="a detailed report showing results of several research projects" />
    </td></tr>
    </table>
    <br />
    <br />
    <input type="submit" value="Submit" />
    </form>



    </body>

    </html>

  4. #4
    Join Date
    May 2009
    Location
    Christchurch, New Zealand
    Posts
    6
    Is there anyone who can help me please?

  5. #5
    Join Date
    May 2009
    Posts
    150
    Use a hidden input for each variable you want to pass and set their values to the values of the variables on submission:

    Code:
    <input type="hidden" name="comprehension" id="comprehension_id" value="0" />
    Code:
    document.getElementById('comprehension_id').value = comprehension;
    However I suggest you look into using forms properly with server side checks.

    a) It means you don't need to rely on javascript to do something which native controls were designed to do and which are pretty well implemented on all major, and I suspect minor, browsers.

    b) It means people can't cheat simply by going to:

    Code:
    ReadingTestPart2.html?ReadingEff=100&comprehension=100&vocab=100&readingRange=100
    Never rely on clients to implement any important functionality; simply submit their answers to the server and do the calculations there.

  6. #6
    Join Date
    May 2006
    Location
    Odenton, MD
    Posts
    1,449
    @beth0902:
    first, important detail! next time you paste code, and specially when it is long, enclose them in BBCode tag [code]...[/code]. is more easier to read code in proper display because it use monospaced font and it will prevent the system board from parsing certain characters which will break your code. when board parse those chars, is hard to anyone to spot the bug in your code.

    i agree with Y_Less. however, i also understand that you're learning javascript. so i guess you will still looking for the solution in javascript. first thing you have to fix is the structure of your form. radio button are meant to select a single option within a group. to do so, you have to give each inputs group the same value in name attribute.
    Last edited by ZeroKilled; 05-18-2009 at 09:20 PM.
    my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous.
    my nature language is javascript, then come spanish and english -- me

  7. #7
    Join Date
    May 2009
    Location
    Christchurch, New Zealand
    Posts
    6

    Thanks!

    Thank you everyone.

    Yes I will try and edit my posts and put the code into one of those boxes.

    By the way what is the code for displaying results in a new window? I've tried searching everywhere but I can't find something that I could use.

  8. #8
    Join Date
    May 2009
    Location
    Christchurch, New Zealand
    Posts
    6

    By the way

    By the way, dumb question I know, how do you edit your own posts? I cannot find an edit button!

  9. #9
    Join Date
    May 2006
    Location
    Odenton, MD
    Posts
    1,449
    after you create a new window with open method and store the returned reference you can begin displaying the information using the stored reference. isn't quite a good solution but you can 'write' to that window with write method. you can pass anything, even html code and/or variable with primitive value (number, string, boolean), and the browser will render it. try following those link, along with the example, which explain how you would use the methods.

    regarding the ability to edit post, each forum have their own rules. in WD, you have 30 minutes or so to edit your post after sending it. once time expire, you can't edit the post.
    my mom is javascript, dad is javascripter, granpa is javascriptor, and my little sister is javasRidiculous.
    my nature language is javascript, then come spanish and english -- me

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles