...

View Full Version : countdown or countup redirect



durangod
12-01-2012, 12:24 PM
Hi, i have a limit i am setting on my chatroom they have a certain mount of time to chat (i have a good reason)

anyway so i have the time set in a var

I post the var on the page "you have this much time" (its depending on the member status)

I got a redirect script but it just does seconds, then i found a few countdown script but all of them had issues either the seconds didnt work or when the seconds go to 09 it froze.

Anyway long story short i been at this for 6 hours now and i cannot seem to find a good script that i can load a value hour min sec into and have it countdown.

or load hour min sec into and have it count from zero to that amount.

i found phils on a thread here but again it only does seconds.

I have tried to take the code from one and put it into another but im totally upside down now. lol

what i start with is this 00:00:00 h m s and i get that by




//creditworth_sec is how many total seconds

$chatallowed = gmdate("H:i:s", $creditworth_sec);



my plan is to redirect when the time is up either count up or count down

thanks




UPDATE i ripped it all out and starting over. I know that phils works, ty phill :) so what i might do is just use his to count down 60 sec at a time on the screen.
then every loop add one to a counter and display that total on the screen in a div, then when that total equals my total do the redirect. i dont do partial min so it will be full min.

how does that sound, to me it sounds so much less complicated than calculating seconds and converting and all that.


UPDATE again lol. Ok i like that i idea forget the original id.

here is what i have i like this much better. ill be back if i need help and phil thanks again nice job .. :)




<script type="text/javascript">

/*author Philip M. 2010*/

var minutes=0;
var timeInSecs;
var ticker;

function startTimer(secs){
timeInSecs = parseInt(secs)-1;
ticker = setInterval("tick()",1000); // every second
}

function tick()
{
var secs = timeInSecs;
if (secs>0)
{
timeInSecs--;
}else {
clearInterval(ticker); // stop counting at zero
startTimer(60); // remove forward slashes in front of startTimer to repeat if required
minutes = minutes + 1;
}//close else


document.getElementById("countdown").innerHTML = secs;
document.getElementById("minutes").innerHTML = minutes;

}//close function tick

</script>

007julien
12-01-2012, 02:45 PM
Numerical strings beginning by 0 are interpreted as hexadecimal integers, then you have to write intSec=parseInt(strSec,10); to transform such a chain to an integer.

Since see this tread from web.developers (http://www.webdeveloper.com/forum/showthread.php?255647-Crazy-Javascript-issue&p=1188287#post1188287) which contains a very good count-down timer

durangod
12-01-2012, 03:14 PM
Thanks for the link. Right now im getting an undefined in the minute var

i dont know why its showing

undefined60

then it goes to

Time Used
NaN26

the seconds is counting fine but, i dont understand what is undefined or i would fix it lol



<script type="text/javascript">

var limit = document.redirect.limit.value;
var targURL="/chatcomplete.php";
var minutes=0;
var timeInSecs;
var ticker;

function startTimer(secs)
{
timeInSecs = parseInt(secs)-1;
ticker = setInterval("tick()",1000); // every second
}

function tick()
{
var secs = timeInSecs;
if (secs>0)
{
timeInSecs--;
}else {
clearInterval(ticker); // stop counting at zero
startTimer(60); // remove forward slashes in front of startTimer to repeat if required
minutes = minutes + 1;

/* if(minutes == limit)
{
window.close(); //this should close the chat window since it is the most current window, it is not named.
//do some other stuff here too
} */

}//close else

007julien
12-01-2012, 03:37 PM
I suppose you call tick() to begin ?
then timeInsecs as no value secs is not bigger than 0...

NB:ticker = setInterval(tick,1000); is better than ticker = setInterval("tick()",1000);

durangod
12-01-2012, 03:45 PM
no i call it by



startTimer(60);

i even added this




timeInMins = parseInt(minutes);

and then this in tick

var minutes = timeInMins;



still get NaN

it was working before i dont get js sometime, seems to make the simplist things the hardest sometimes..

Here is the whole thing form and all as it is, i commented our some stuff to try to trouble shoot




<em>Time Used</em><br />
<span id="minutes">00</span>
<span id="countdown">60</span>


<?php

//now split time up into array so you can pass min to js
//this will be passed to form and js for the limit var
$alow_array = explode(":",$chatallowed);
$alhour = $alow_array[0]; //hours
$almin = $alow_array[1]; //min

?>

<script type="text/javascript">

/* var limit = document.redirect.limit.value; */
/* var targURL="/chatcomplete.php"; */
var timeInSecs;
var ticker;

function startTimer(minutes,secs)
{
timeInSecs = parseInt(secs)-1;
timeInMins = parseInt(minutes);
ticker = setInterval("tick()",1000); // every second
}

function tick()
{
var minutes = timeInMins;
var secs = timeInSecs;
if (secs>0)
{
timeInSecs--;
}else {
clearInterval(ticker); // stop counting at zero
startTimer(60); // remove forward slashes in front of startTimer to repeat if required
var minutes = minutes + 1;

/*
if(minutes == limit)
{
window.close(); //this should close the chat window since it is the most current window, it is not named.
window.location=targetURL;
return;
//do some other stuff here too
}
*/

}//close else


document.getElementById("countdown").innerHTML = secs;
document.getElementById("minutes").innerHTML = minutes;
}//close function tick



</script>


<center>
<form name="redirect" id="redirect" action="javascript:popUp('avchat/index.php');">
<input type="hidden" name="limit" id="limit" value="<?=$almin;?>" />
<input type="submit" name="submit" value="Start Chatting" class="button" onclick="startTimer(60);" />
</form>

<form name="frmstop" method="post" action="chat_complete.php">
<input type="submit" class="button" name="stopchat" value="Stop Chatting" />
</form>
</center>

durangod
12-01-2012, 03:55 PM
i went back to the one in my first post, bottom that actually works, then i will trouble shoot as i go. thanks...

I just need to add the limit as well as close it all down when i add the redirect, but i will take it one step at a time. again thanks

durangod
12-01-2012, 04:37 PM
ok quick question, im almost there wheeww lol

how do i pass the value of incremented minutes to the form

i want to pass


<span id="minutes">00</span>:

to


<input type="hidden" class="button" name="used" id="used" value="<?=$used;?>" />



maybe like this, is this how?


document.getElementById("used").innerHTML=minutes;

007julien
12-01-2012, 04:46 PM
Do not use minutes and seconds, but only timeInSecs and call startTimer with minutes and seconds with something like this startTimer(0,60) or startTimer(1,0) (for 1 minute)

var timeInSecs;
var ticker;

function startTimer(minutes,secs){
timeInSecs = minutes*60+secs-1;
ticker = setInterval(tick,1000); // every second
}

function tick() {
var minutes = Math.floor(timeInSecs/60);
var secondes = timeInSecs%60;
if (timeInSecs>0) {
timeInSecs--;
}else {
clearInterval(ticker); // stop counting at zero
startTimer(60); // remove forward slashes in front of startTimer to repeat if required
var minutes = minutes + 1;

/*
if(minutes == limit)
{
window.close(); //this should close the chat window since it is the most current window, it is not named.
window.location=targetURL;
return;
//do some other stuff here too
}
*/

}//close else


document.getElementById("countdown").innerHTML = secondes;
document.getElementById("minutes").innerHTML = minutes;
}//close function tick

durangod
12-01-2012, 04:51 PM
got it


document.getElementById('used').innerHTML=minutes;

does it make any difference if i use single quotes around input name or double quotes?

and on this part below, do i need the return if i am closing everything out and redirecting?



if(minutes >= limit)
{
window.close(); //this should close the chat window since it is the most current or top window, it is not named.
window.location=targURL;
return;
//do some other stuff here too
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum