Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Submiting a form while redirecting under a timer.

Status
Not open for further replies.

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:
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>
 
You have one page. You can either submit the form to the processing page, or redirect to another page.

In real life, if you have one car, you can only drive it to one destination at a time. You can't drive the car to Reno and Las Vegas at the same time, but you can drive to Reno THEN Las Vegas.

Lee
 
The form submits it to itself or redirects depending on an existence of the variable "pageid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top