CMCDragonkai
Programmer
- May 17, 2008
- 2
I have this code:
The script at the top (Look at the bottom of this post to see the full script), specifies, the div id which is CountDownPanel in which the timer is to be placed, and 10 is the amount of seconds.
At this place, (Scroll down to see the full script)
Code:
pageid is the variable of the page url in which the page redirects to. At this moment pageid is it self, so it redirects to itself.
The problem is, is that I also have a form. So basically, it's kind of like a test.
In which, there is a timer, and when that timer counts to zero. It is supposed to redirect back to itself while submitting it's form. There of course is also a submit button if they finish under the time. But I don't know how to redirect and submit the form at the same time.
Any help is appreciated.
The Full Code:
Code:
The script at the top (Look at the bottom of this post to see the full script), specifies, the div id which is CountDownPanel in which the timer is to be placed, and 10 is the amount of seconds.
At this place, (Scroll down to see the full script)
Code:
Code:
function CountDownTick() {
if (_currentSeconds <= 0) {
alert("Your Time Is Up!");
document.location = pageid;
return;
}
pageid is the variable of the page url in which the page redirects to. At this moment pageid is it self, so it redirects to itself.
The problem is, is that I also have a form. So basically, it's kind of like a test.
In which, there is a timer, and when that timer counts to zero. It is supposed to redirect back to itself while submitting it's form. There of course is also a submit button if they finish under the time. But I don't know how to redirect and submit the form at the same time.
Any help is appreciated.
The Full Code:
Code:
Code:
<script type='text/javascript'>
window.onload=WindowLoad;
function WindowLoad(event) {
ActivateCountDown('CountDownPanel', 10);
}
</script>
<script type='text/javascript'>
var _countDowncontainer=0;
var _currentSeconds=0;
function ActivateCountDown(strContainerID, initialValue) {
_countDowncontainer = document.getElementById(strContainerID);
if (!_countDowncontainer) {
alert("count down error: container does not exist: "+strContainerID+
"\nmake sure html element with this ID exists");
return;
}
SetCountdownText(initialValue);
window.setTimeout("CountDownTick()", 1000);
}
function CountDownTick() {
if (_currentSeconds <= 0) {
alert("Your Time Is Up!");
document.location = pageid;
return;
}
SetCountdownText(_currentSeconds-1);
window.setTimeout("CountDownTick()", 1000);
}
function SetCountdownText(seconds) {
//store:
_currentSeconds = seconds;
//get minutes:
var minutes=parseInt(seconds/60);
//shrink:
seconds = (seconds%60);
//get hours:
var hours=parseInt(minutes/60);
//shrink:
minutes = (minutes%60);
//build text:
var strText = AddZero(hours) + ":" + AddZero(minutes) + ":" + AddZero(seconds);
//apply:
_countDowncontainer.innerHTML = strText;
}
function AddZero(num) {
return ((num >= 0)&&(num < 10))?"0"+num:num+"";
}
</script>