multiple instances of same function

Custom / CUSTOM
June 30, 2010 at 01:55:58
Specs: Windows 7, 8g
Hey there,

I am trying to add multiple javascript
countdown's to a webpage and I admit am still
very new to javascript. I cannot manage to
autostart more then one instance at a time.

I am using a combination of PHP/JS/HTML on
the page. PHP is used to calculate the
number of seconds left and to loop through
how many instances are needed. Here is my
JS code. As you can see I don't think I can
have it auto load in the body because the
#seconds will not have been calculated yet.
Feel free to recommend and new scripts.

<script type="text/javascript"> 
function display_c(start){
window.start = parseFloat(start);
var end = 0 // change this to stop the counter 
at a higher value
var refresh=1000; // Refresh rate in milli 
if(window.start >= end ){
else {mytime=setTimeout('done()',refresh)}

function display_ct() {
// Calculate the number of days left
//var days = Math.floor(window.start / 86400); 
// After deducting the days calculate the 
number of hours left
var hours = Math.floor(window.start /3600)
// After days and hours , how many minutes 
are left 
var minutes = Math.floor((window.start - (hours 
*3600 ))/60)
// Finally how many seconds left after 
removing days, hours and minutes. 
var secs = Math.floor((window.start - (hours 
*3600 ) - (minutes*60)))

var x = hours + ":" + minutes + ":" + secs;
var y = "Done!";

document.getElementById('ct').innerHTML = x;
window.start= window.start- 1;


function done() {
var y = "Done!";
document.getElementById('ct').innerHTML = y;

<body onload=display_c(# of seconds left 
found by php function.)>
<span id=ct></span>

See More: multiple instances of same function

Report •

June 30, 2010 at 02:09:07
How about jQuery countdown?

Report •

July 4, 2010 at 12:01:08
You need to give each countdown a number e.g. 1, and then duplicate all the functions and just add the number of the countdown onto the end of the function's name.


Report •

Related Solutions

Ask Question