PDA

View Full Version : Display Countdown Time Remaining



penster1
03-04-2008, 09:42 PM
1) Script Title: Universal Countdown

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex6/universalcountdown.htm

3) Describe problem:
Where do i change the script so that when days remaining = 0 it will only display hours, minutes, secs, If hours = 0, then it will only show minutes and secs, etc.

launchdate.displaycountdown("days",

Examples:
0 days 23 Hours 54 Minutes 38 Seconds//
23Hours 54Min 38Secs//Correct Display Would show this

0Hours 54Min 38Secs//
54Min 38Secs//Correct Display Would show this

Master_script_maker
03-04-2008, 10:13 PM
add this code:

function noblank() {
if (this.timesup==false){//if target date/time not yet met
var displaystring="<span>";
arguments[0]=(arguments[0]==0 && arguments[0]=="0")?"":arguments[0]+" days ";
arguments[1]=(arguments[1]==0 && arguments[1]=="0" && arguments[0]=="")?"":arguments[1]+" hours ";
arguments[2]=(arguments[2]==0 && arguments[2]=="0" && arguments[1]=="")?"":arguments[2]+" minutes ";
arguments[3]=(arguments[3]==0 && arguments[3]=="0" && arguments[2]=="")?"":arguments[3]+" seconds";

displaystring+=arguments[0]+arguments[1]+arguments[2]+arguments[3]+"</span> left until launch time";
} else { //else if target date/time met
var displaystring="Launch time!"
}
return displaystring
}
and when you use the displaycountdown() function use this: displaycountdown("days", noblank)

ddadmin
03-05-2008, 12:29 AM
Inside your call back function used to display the output, you would simply do a simple test on arguments[0] (day field) for the value 0, and mold the output accordingly. So whereas before you may have this:


function formatresults(){
if (this.timesup==false){//if target date/time not yet met
var daysfield=(arguments[0]==0)? "" : arguments[0]+" days "
var displaystring="<span style='background-color: #CFEAFE'>"+arguments[0]+" days "+arguments[1]+" hours "+arguments[2]+" minutes "+arguments[3]+" seconds</span> left until launch time"
}
else{ //else if target date/time met
var displaystring="Launch time!"
}
return displaystring
}

You would change that slightly to:


function formatresults(){
if (this.timesup==false){//if target date/time not yet met
var daysfield=(arguments[0]==0)? "" : arguments[0]+" days "
var displaystring="<span style='background-color: #CFEAFE'>"+daysfield+arguments[1]+" hours "+arguments[2]+" minutes "+arguments[3]+" seconds</span> left until launch time"
}
else{ //else if target date/time met
var displaystring="Launch time!"
}
return displaystring
}