PDA

View Full Version : Timed Submit Button


Muffin_LA
07-11-2005, 15:03/03:03PM
Hi everyone:

I created a quiz that is timed. The user has 10 minutes to complete it or they have to start over. If the user clicks the submit button after 10 minutes then an alert tells them they must start over again.

I can get the alert to pop up after the time limit but I cant figure out how to get it only to pop up when the user clicks the submit button and its over the 10 minute time limit.

Any suggestions?

Thanks
Linda

Connie
07-11-2005, 15:36/03:36PM
Linda I can't help but it might help you to get the answer if you posted the javascript. My guess is that you may only need a minor change to what you have to add the timeout to what you have.

Muffin_LA
08-11-2005, 00:07/12:07AM
Thanks Connie. I had planned to add it but was in a hurry when I left the message and I forgot.

This is my latest script. When I cant get something to work I make another one and work on it.
Maybe someone can spot the problem.

var answers = new Array(5);
var correctAnswers = new Array(5);
correctAnswers[0] = "b";
correctAnswers[1] = "c";
correctAnswers[2] = "a";
correctAnswers[3] = "c";
correctAnswers[4] = "d";
function recordAnswer(question, answer) {
answers[question-1] = answer;
}

function confirmSubmit() {
var submitForm = window.confirm("Are you sure you are ready to submit your quiz?");
if (submitForm == true)
return true;
return false;
}
function confirmReset() {
var resetForm = window.confirm("Are you sure you want to reset the form? Remember you only have 10 minutes to complete this quiz.");
if (resetForm == true)
return true;
return false;
}

// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
</head>
<body onload="setTimeOut('document.forms[0].submit(), 600)">

<form action="" method="get"
enctype="application/x-www-form-urlencoded"
onsubmit="return confirmSubmit();"
onreset="return confirmReset();">
<p><input type="submit" value="Submit" />
<input type="reset" /></p>

Thanks again
Linda

Muffin_LA
09-11-2005, 15:00/03:00PM
Hi everyone:

I have the script working for the most part. My problem is I have a problem with the arguement I think.

If I click the submit button after the time limit is up. it first asks if I am sure i want to submit it, then the alert comes up saying I have went over the time allowed and must start over.

I need for the last alert to just come up because the user can not submit the quiz if they are over the time limit.(I have set the time very low so I dont have to wait to see if its working properly).

Any help would be greatly appreciated. Thank you
Linda

Here is the code:

var answers = new Array(5);
var correctAnswers = new Array(5);
correctAnswers[0] = "b";
correctAnswers[1] = "c";
correctAnswers[2] = "a";
correctAnswers[3] = "c";
correctAnswers[4] = "d";
function recordAnswer(question, answer) {
answers[question-1] = answer;
}
function timesUp () {
var buttonNotPressed = setTimeout("alert('You have taken too much time to complete the quiz. Please use the browsers Refresh Button to start over.')", 60);
if (buttonNotPressed == true)
return false;
else {
if (buttonNotPressed > 60);
return true;
}
}
function confirmSubmit() {
var submitForm = window.confirm("Are you sure you are ready to submit your quiz?");
if (submitForm == true)
return true;
return false;
}
function confirmReset() {
var resetForm = window.confirm("Are you sure you want to reset the form? Remember you only have 10 minutes to complete this quiz.");
if (resetForm == true)
return true;
return false;
}

// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
<form action="" method="get"
enctype="application/x-www-form-urlencoded"
onsubmit="return confirmSubmit();"
onreset="return confirmReset();">
<p><input type="submit" value="Submit" onclick="timesUp();" /><input type="reset" /></p>
</form>