|
-
Nov 9th, 2006, 05:39 PM
#1
Thread Starter
Hyperactive Member
[JavaScript]Stopping or atleast knowing if browser was refreshed
What would be the best way to stop a page from being refreshed by a user or atleast tell if it was. What I am doing is writing a page for Students to take a small quiz and as it is right now, they are able to refresh the browser and re-answer question to get the correct answer (questions are multiple choice). my first thought would be to make a function that stored the student name in a file on the start of the quiz, then when ever the student refreshes the page, check that file.
Any thoughts would be greatly appreciated 
(and code if you have it)
-
Nov 10th, 2006, 04:15 AM
#2
Re: [JavaScript]Stopping or atleast knowing if browser was refreshed
Personally I'd use a Database to store all the questions and all the students answers. Have a page that loads the next question that does not have an answer. Once the student answers the question update the DB and reload the page. You may also want to add navigation so that the students can skip questions in order to come back and answer them later.
Edit:
Using a DB makes changing questions and reporting their results trivial.
-
Nov 10th, 2006, 05:45 AM
#3
Re: [JavaScript]Stopping or atleast knowing if browser was refreshed
Although this would require use of a server side language and dropping JavaScript as there is no real need for it. Of course you could do some validation on client side with JS, but you should validate on the server side as well to prevent cheating.
-
Nov 10th, 2006, 10:38 AM
#4
Thread Starter
Hyperactive Member
Re: [JavaScript]Stopping or atleast knowing if browser was refreshed
Well so far im trying to keep away from a DB as it would mean a lot of work when we could just put this down on paper and be done with it. What I have done so far is im using the onunload event in the BODY tag to catch a refresh or close, and it calls a function. But my function isn't sending the form out(when page is being refreshed) to the asp page that I set up to handle the form.
Here is my code:
VB Code:
function OnExit() {
alert('You answers are now being submitted');
document.getElementById("textResults").value = score;
document.quizform.submit();
}
Can sending a form out to a diff page when the current page is being refreshed be done?
-
Nov 10th, 2006, 10:57 AM
#5
Re: [JavaScript]Stopping or atleast knowing if browser was refreshed
Well so far im trying to keep away from a DB
Losing battle. Best to give in before you get to the point of realising you do need a database and it is too hard to convert what you already have.
-
Nov 10th, 2006, 11:07 AM
#6
Thread Starter
Hyperactive Member
Re: [JavaScript]Stopping or atleast knowing if browser was refreshed
Well everything works if I use the submit button. It just seems when a user refreshes the browser and my Exit function is performed, the form isn't being submitted at all (I get the alert though). So I take it that this is not possible?
Or am I doing something wrong?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|