/    Sign up×
Community /Pin to ProfileBookmark

Newbie needs help with a countdwodn script

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:

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@MrEnderJan 26.2010 — Do you have to use cookies? Cause if not here is a clock example you can preview that might help you on your quest

function startTime() {


var d = new Date();
var PMCheck = "";
var h = d.getHours();
var m = d.getMinutes();
var s = d.getSeconds();
var hourCheck = h;
var displayHours = h;
if(hourCheck>=12) {

PMCheck = " PM";

}
else {

PMCheck = " AM";

}
if(displayHours>=13) {

displayHours-=12;

}

m=checkTime(m);
s=checkTime(s);
document.getElementById("footerClockDiv").innerHTML=displayHours+":"+m+PMCheck;
t=setTimeout('startTime()',500);

}

function checkTime(i) {

if (i<10) {
i="0" + i;
}

return i;


}

function getWeekDay() {

var wk = "";

var d = new Date();
var weekday = new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

wk = weekday[d.getDay()] + ",";
t=setTimeout('startTime()',500);

return wk;


}

function getMonthName() {

var mth = "";

var d = new Date();
var month = new Array(12);
month[0]="January";
month[1]="Febuary";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";

mth = " " + month[d.getMonth()] + " ";
t=setTimeout('startTime()',500);

return mth;


}

function getDayNumber() {

var day = d.getDate();

t=setTimeout('startTime()',500);

return day;


}

function getExtraZero() {

var extraZero = "";

if(getDayNumber()<=9) {

extraZero = "0";

}
else if(getDayNumber()>=10) {

extraZero = "";

}

t=setTimeout('startTime()',500);

return extraZero


}

date = " " + getWeekDay() + getMonthName() + getExtraZero() + getDayNumber() + ", " + year;

function clockMouseover() {

document.getElementById("clockHoverDiv").innerHTML = date;
document.styleSheets[2].disabled = false;


}

function clockMouseout() {

document.getElementById("clockHoverDiv").innerHTML = '';
document.styleSheets[2].disabled = true;


}

Appologies if any of the variables are missing not sure if I did that global or not. Don't remember.

oh ya you will need

<body onload=startTime()>
Copy linkTweet thisAlerts:
@MrEnderJan 26.2010 — also forgot you need

<div id="footerClockDiv">&nbsp;</div>
Copy linkTweet thisAlerts:
@KefaloauthorJan 26.2010 — yep, cookies are essential..thanks anyway..?
Copy linkTweet thisAlerts:
@MrEnderJan 26.2010 — yep, cookies are essential..thanks anyway..?[/QUOTE]

I avoid cookies like the plague so sorry can't help =[ I only use them for remembering user names/passwords and that I usually slip up on lol
×

Success!

Help @Kefalo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...