Click to See Complete Forum and Search --> : beginner gone mad!


enclosed
12-06-2003, 03:25 AM
i desperately need some assistance. i admit i'm a beginner
and i believe what i am wanting to happen is a bit too difficult
for me to seek out on my own. *embarrassed*

anyways...

i'd like to have a visible countdown timer on a particular page.
i'd like to set my own time variables... and i'd like the timer
to react once per browser session. (i only want to set the
timer for about 5 minutes)

upon hitting zero (on the timer) a popup alert should come
up messaging the user that they will be redirected to a new
page in, say, 10-15 seconds.

i would like the redirection to happen within the same window
(without opening a new window).

am i asking for the world here? because it has me stumped
on how to achieve this *seemingly* simple task
:o

thanks for any advice


EDIT --

crap... i forgot to mention that i need the timer to begin
as soon as the page loads...... :(

enclosed
12-06-2003, 03:32 AM
sorry to double post... but i realized something while typing
out my issue....

i suppose it IS possible that i could be wanting a counter
that redirects upon zero... but to suspend the redirection
for about 10 seconds... in which a popup alert happens.

i realize that the issue of users and their compatabilities
come into play... but this project i'm working on will only
be seen by one person other than me.

in fact... i'm working on a christmas present

thanks again for any help

Pittimann
12-06-2003, 04:00 AM
Hi!

What browser and OS the stuff will be viewed in??
Can you please post that?

Cheers - Pit

enclosed
12-06-2003, 04:06 AM
hi and thanks...

IE 6 and XP

Pittimann
12-06-2003, 04:57 AM
Hi!

Here's some code (I asked for your browser, because this code will not work in every browser - in IE no problem!):

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script language="JavaScript" type="text/javascript">
<!--
var textBeforeCountdown="You've got another "
var textAfterCountdown=" to go before redirect..."
var seconds = 15;//for 5 minutes put 300 here; will work properly upto 599 seconds
var secondsAfterAlert = 10;//seconds to wait after clicking ok in alert
var yourUrl="xmas.html";//page to which redirect goes
var timer;
function countDown() {
if (seconds>=60){
minutes=""+seconds/60;
minutes=minutes.substring(0,1);
if (minutes!="1") mPlural="s";
else mPlural="";
minutes2=minutes+" minute"+mPlural+" and ";
seconds2=seconds-minutes*60;
if (seconds2!=1) seconds2=seconds2+" seconds";
else seconds2=seconds2+" second";
timerSpan.innerHTML=textBeforeCountdown+minutes2+seconds2+textAfterCountdown;
}
else{
if (seconds!=1) seconds2=seconds+" seconds";
else seconds2=seconds+" second";
timerSpan.innerHTML=textBeforeCountdown+seconds2+textAfterCountdown;
}
if(seconds ==0) {
stopTimer();
}
seconds--;
if(seconds >=0) timer=window.setTimeout("countDown()",1000);
}
function stopTimer() {
clearTimeout(timer);
alert("Redirection "+ secondsAfterAlert + " seconds after clicking 'OK'");
timerSpan.innerHTML="Be patient and Merry XMAS!!!";
window.setTimeout('window.location="'+yourUrl+'"',secondsAfterAlert*1000)
}
//-->
</script>
</head>
<BODY onload="countDown()">
<!-- put this span where you need it: -->
<span id="timerSpan"></span>
</body>
</html>

If you need a hand for more adjustments, just post again...

edit: please remove the space between "timerSpan." and "innerHTML" wherever it occurs...

Cheers - Pit

enclosed
12-06-2003, 05:04 AM
OH!!!!!

forgive me for saying, but i think that almost brought a
tear to my eye. you don't know how much i appreciate that!!

oh! thank you so very much!

i'll test it out on my project and see how it meshes together...


thank you again!!!!

Pittimann
12-06-2003, 05:07 AM
You're welcome!!

Take it as a gift sent from Santa Claus :D

Cheers - Pit