Skip to content Skip to sidebar Skip to footer

Unable To Retrieve A Variable After Being Passed From Javascript

I have 3 html pages where 2 pages each have question 1 and question 2. The 3rd page shows the score of the test. I have designed the pages and now i want to keep track of the user

Solution 1:

Sorry if my comments seemed harsh, but I am all about new coders learning the basics themselves without relying on having the answers provided. Just to show it can be done - I just created three HTML pages. Created a form in the first two - each with your questions (questions 1 and 2 in the first page and question 3 in the second page), and passed the form values to the next one, using nothing more than html.

Then using only JavaScript on the second and third pages, I grabbed the values out of the URL and did stuff with them. On page two, I re-used the values from page 1 (think how that might have been done and why it is useful) so that all three values are passed to page 3 which then used JavaScript only to grab the 3 values, display them on the page (as shown in the code section below) and calculate the total and the percentage of answers that are correct. Note that I answered the questions so that I got question 2 incorrect.

Note that I am not giving the code used, but will give you the URL of the pages so that you can see the outcome of the previous two pages and can then start to think how I achieved this.

numbers1.html
numbers2.html?one=correct&two=incorrect
numbers3.html?one=correct&two=incorrect&three=correct

Question 1: correct

Question 2:incorrect

Question 3:correct2/30.67% correct

Not a traditional answer I know, but it is not ideal for learners simply ask for the answer to be provided, especially when in 10 minutes I was able to put together the three pages that achieved the outcome. If you do not try then you will not learn for yourself.

General note: two forum members and I spent a lot of time this afternoon trying to assist the OP with the code required - giving code examples. so this post is more about teaching than providing answers. I wish I had teachers like that to inspire research and understanding before simply asking for the answer. So now that I have said that - feel free to down vote, but I stand behind my philosophy and will not delete this answer, simply to not get downvotes. This forum must be a teaching environment as well as a code repository.

Post a Comment for "Unable To Retrieve A Variable After Being Passed From Javascript"