Hi everybody,
this is my first post and it seems like it’s a great crowd here. I am in urgent need of a solution for my issue. I need a script that will perform an irregular countdown on a page for specific customers.
What I’m saying is this:
-field that says 20 when a customer first logs in
-it says 19 after some time (10 minutes for example)
-the countdown continues to 15 with the interval of say 20 minutes
-the countdown continues with 30 minutes interval
-the countdown continues with 12 hours interval
I hope you get the idea. If I am not clear enough, here is the code that I have at the moment that my friend help me with but we could not get it to work. After 10 minutes it just starts blinking 20-19.20-19….and so on, and I am not sure why…
Here’s the code…
<script type=’text/javascript’>
var initTime;
var currentTime = new Date();
currentTime = Math.round(currentTime.getTime()/1000);
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ “=” +escape(value)+
((expiredays==null) ? “” : “;expires=”+exdate.toGMTString());
}
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + “=”);
if (c_start!=-1)
{
c_start=c_start + c_name.length+1;
c_end=document.cookie.indexOf(“;”,c_start);
if (c_end==-1) c_end=document.cookie.length;
return unescape(document.cookie.substring(c_start,c_end));
}
}
return “”;
}
function checkTime() {
var seconds;
var x = document.getElementById(‘timer’).innerHTML;
if(x == 20) { seconds = 300; }
else if(x == 19 && x >= 16) { seconds = 1800; }
else if(x == 15) { seconds = 2400; }
else { seconds = 43200; }
var timeElapsed = Math.round( 20 – (Math.floor(currentTime – initTime)/seconds) );
if(timeElapsed < 2) { timeElapsed = 2; }
var el = document.getElementById(‘timer’);
var ela = document.getElementById(‘timera’);
var elb = document.getElementById(‘timerb’);
var elc = document.getElementById(‘timerc’);
if(el.innerHTML == timeElapsed) { }
else {
el.innerHTML = timeElapsed;
ela.innerHTML = timeElapsed;
elb.innerHTML = timeElapsed;
elc.innerHTML = timeElapsed;
}
currentTime++;
if(timeElapsed == 2) { return false; }
else { setTimeout(“checkTime();”,1000); }
}
if(!getCookie(‘timer’)) {
initTime = new Date();
initTime = Math.round(initTime.getTime()/1000);
setCookie(‘timer’,initTime);
}
else { initTime = getCookie(‘timer’); }
window.onload = checkTime;
</script>
:eek::eek::eek::eek::eek: