0

I have a code for countdown timer and it works perfectly fine..

<html>
<title>project prelim</title>
<head>
<script type="text/javascript">
var ss = 10;

function countdown() {
ss = ss-1;

if (ss<0) {
window.location="testover.html";
}
else {
document.getElementById("countdown").innerHTML=ss;
window.setTimeout("countdown()", 1000);
}
}
</script>

</head>
<body onload="countdown()">
<center>
<table width="100%" height="600px" style="text-align:center;">
<tr><td valign="center"><h3>Redirecting to testover <h2 id="countdown"></h2></h3></td></tr>
</table>
</center>
</body>
</html>

Now if I am implementing it in a form which has a button like

<form action="batman.php" method="post">


<button id="submit" type="submit" >Submit</button>


</form>

The code which I have does not do the form submit action. How can I make the form submit action happen automatically as soon as the timer runs out .

3
Contributors
5
Replies
18
Views
2 Years
Discussion Span
Last Post by bdanie
0

I think something like this should work:

document.getElementById('submit').click();

But why the hell are you creating a countdown redirect if nothing actually happens during the countdown? :p

0

Why would you scare the hell out of somebody by saying this form will be submitted in 10...9...8... seconds? Submission of forms should be under the control of the user - especially if you have a submit button.

I'd rather see a 'disable' button event and 'too late' message. Maybe you have a unique use case. WHat are you trying to do exactly? Is this some sort of online test?

0

Yes, it is for an online test sort of a thing. I'm in very early stages development and the above code is just a sample of what I'm going to do actually. It is a test of duration 10 minutes and I give the user the liberty to submit whenever he feels like within the 10 minute duration and as soon as the 10th minute is over I want to automatically submit the form and redirect the user to another page !

0

OK, just be aware that scripts like these can be bypassed with things like Tamper/Greasemonkey. So, effectively, giving your user unlimited time to complete the test. Ensure that the times are logged server side too to catch out potential clever dicks.

0

This test will happen in systems at our place and it will run in localhost with just LAN connectivity with no Internet connection ! Our systems run CentOS and users will have access to a user account where they cant acutally change any of the system settings. Thanks All !!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.