problem: javascript counter

They have: 4 posts

Joined: Mar 2006

hi! i have a little quetsion, i copyed this script from a webpage, but it doesent work very good.

this is the script.

<script type="text/javascript">
function contar(minutes,seconds) {

  fecha=new Date(0,0,0,0,minutes,seconds); //año,mes,dia,hora,minuto,segundo
  ahora=new Date();
  dif=new Date(fecha-ahora);

  txt=dif.getMinutes()+' '+dif.getSeconds();
  document.getElementById('clock').innerHTML=txt;

}
</script>
<body onload="setInterval('contar(5,0)',1000)">
<span id="clock"></span>
</body>
'

i want a countdown of 5 minutes to 0 m. but if i run this code, it doesnt work like that. i dont know why Sad

please help me! ty!! byee

pcmedicplus's picture

He has: 49 posts

Joined: Mar 2006

Found this @ [URL]http://www.sivamdesign.com/scripts/clocks.html [/URL]

<script language="JavaScript" type="text/javascript">

</script>

They have: 4 posts

Joined: Mar 2006

ty!! it works

They have: 4 posts

Joined: Mar 2006

pcmedicplus hi!

how can i do, to use the function 2 or more times with different times in a site? i mean, if i copy the function and then i change the line

if (document.getElementById) { theTime2.innerHTML = time; }

<tr><td width="100%" align="center"><span id="theTime2" class="timeClass"></span></td></tr>
'
i tried so, everything works, but when the first time stop (the one from 5 to 0) the second time (from 15 to 0) stop in 10.00 and it doesnt work anymore.

any idea how can i lose that problem? ty!!

Busy's picture

He has: 6,151 posts

Joined: May 2001

you'd have to change the onload option and call the function manually with the desired count down times, the minsutes is also hardcoded so will have to become a global

They have: 4 posts

Joined: Mar 2006

busy hi! i tried to do that but it doesnt work. i dont know almost nothing of js. can u copy/paste the code of pcmedicplus and make the changes for me pls?? ty!!

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.