Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing javascript variables between pages [duplicate]

Possible Duplicate:
Persist javascript variables across pages?
how to exchange variables between two html pages

I am working on creating a "quiz" that allows users to answer questions, then passes their answer and current score to the next page for the next question. I used this article and was able to get the user's answer to pass through to the next window:

http://www.htmlgoodies.com/beyond/javascript/article.php/3471111/A-Quick-Tutorial-on-JavaScript-Variable-Passing.htm

The issue is that this passes the information through a form. Once I receive the score on the second page, I need to increment the score if the answer was correct. I can't figure out how to pass a javascript variable with an html form.

I feel like this should be a relatively easy fix, I'm just stumped.

Any thoughts or advice would be much appreciated! xoxo

like image 641
Rachel Rine Avatar asked Jul 20 '12 14:07

Rachel Rine


2 Answers

There are two obvious ways to maintain state in the browser without requiring that the server remember it between pages:

  1. Cookies

  2. localStorage

The latter is trivial to implement, but is only available in HTML5.

Note that neither is intended to be secure - a determined page hacker could set either to whatever value they wish.

like image 168
Alnitak Avatar answered Oct 26 '22 22:10

Alnitak


You can submit a form using get method <form method="get" then use javascript to parse params in url. Reference here:

like image 36
James Avatar answered Oct 26 '22 23:10

James