0

I have a technical challenge that I'm trying to figure out the best way to solve. Here's the scenario.

I have one HTML page that launches another HTML page...let's call it main.html that has a button which calls test.html Inside test.html the user can answer a series of questions and submit the results to a Learning Management System. Each time they do a test I have a JavaScript variable inside the test.html page that gets incremented from A to B to C, etc. For example, if they take the test the first time it will Be something like 0001A and the second time 0001B.

This works great, but if they close the test.html page, since this JavaScript variable is inside it, the counter will start off at 0001A again if the user tries to take another test. What I would like is for the next test the user submits to be 0001C. Not sure how to do this...

I thought of passing a variable to the test.html page via something like: test.html&id=C but this means that main.html that calls test.html would need to know that the user has already done two tests and I'm not sure you can pass a value back from an HTML page to the HTML page that called it?

Anyway, I'm wondering what would be the best way to solve this problem?

Thanks

1
  • Also, are you storing anything in a database? seems like you could load the current test number by looking at that based on submissisons? Commented Jul 7, 2012 at 6:39

1 Answer 1

2

I think that the best way to solve this problem would be by setting a Cookie in the browser via JavaScript:

document.cookie = 'mycookie=testcookie; expires=Sun, 8 Jul 2012 20:47:11 UTC; path=/';

You can easily obfuscate or encrypt this cookie to prevent alteration. Here's a good guide on creating cookies using JavaScript.

Sign up to request clarification or add additional context in comments.

1 Comment

A cookie is a straightforward way to do this, but you cannot prevent alteration by the user. If that's important, then the data has to be kept server-side as data stored on the client can always be altered.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.