Results 1 to 6 of 6

Thread: [JavaScript]Stopping or atleast knowing if browser was refreshed

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    Question [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)

  2. #2
    Frenzied Member DeadEyes's Avatar
    Join Date
    Jul 2002
    Posts
    1,196

    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.

  3. #3
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    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:
    1. function OnExit() {
    2.     alert('You answers are now being submitted');
    3.     document.getElementById("textResults").value = score;
    4.     document.quizform.submit();
    5.    
    6. }

    Can sending a form out to a diff page when the current page is being refreshed be done?

  5. #5
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2004
    Posts
    326

    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
  •  



Click Here to Expand Forum to Full Width