There is a good number of approaches, I want to point out two of them, more modern ones. I like them because they are more universal; in particular, they don't depend on what technology you use on the server side, and applicable even if you don't have server side at all (let's say, for some applications).
One approach is having multiple pages and sharing data between them purely on the client side, using just the browser features. This can be done using
Web storage:
https://en.wikipedia.org/wiki/Web_storage[
^].
You can chose between
window.localStorage
and
window.sessionStorage
:
https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API[
^],
https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage[
^],
https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage[
^].
Session storage is much easier, because you won't need to clear the data from the browser; if you fail to do so or just ignore this problem, the data will be eventually removed by the browser after the session has ended. With local storage, you will have to remove this data in your code, to avoid contamination of your browser's data, but you may need it if you want to continue your quiz between sessions.
Now, Web storage, essentially, works only with strings. Very likely, you will prefer storing data in more complex structures, possibly all by one key. Then you can use
serialization (
http://en.wikipedia.org/wiki/Serialization[
^]). How? JSON, of course;
JSON.stringify
and
JSON.parse
:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON[
^],
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify[
^],
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse[
^].
Note that you don't need to deal with JSON string itself, you only serialize and deserialize your data. In my article, you can find the simple code showing the technique, Web storage with JSON:
JavaScript Calculator, 7. Dynamic Strict Mode Switching and Web Storage.
Another approach is to develop the whole quite in a single page. It's pretty easy to achieve if you break the content in smaller part and show one part at a time, hiding other parts. In this approach, you won't need to exchange any data between pages. See also:
https://en.wikipedia.org/wiki/Single-page_application[
^].
—SA