kinshuk2jain 0 Newbie Poster
<input type="button" value="start" onClick="set(0,0,20)" />

i want to make a countdown timer, and i am using the javascript code mentioned below. Also , to start the timer, i use the button 'onClick' event(written above). The problem is that the clearTimeout() is not working. The countdown timer never stops . Any help is highly appreciated

var t;
var h=0,m=0,s=0;
var tem;

function timer()
{

 if(s==-1)
 {
   m=m-1;
   s=59;
 }
 if(m==-1)
 {
  m=59;
  h=h-1;
 }

if(s<10&&m==0&&h==0&&s>=0)
{
 document.getElementById('tim').innerHTML='<img src="./images/'+s+'fdr.gif" />';
 if(s==0)
 {
   stopTimer();
 }
}
else
{
  if(s<10&&m<10&&m>0&&s>0)
  { 
	  tem="0"+s;
	  s=tem;tem=0;
	  tem="0"+m;
	  m=tem;
	  tem=0;
  }
  else if(s<10&&s>0) 
  {
	  tem="0"+s;
	  s=tem;
	  tem=0;
  }
  else if(m<10&&m>0)
  {
	  tem="0"+m;
	  m=tem;
	  tem=0;
  }
     
  	  document.getElementById('tim').innerHTML=h + ":" + m + ":" + s;  
}
 
 s=s-1;
 t=setTimeout('timer();',960);
 
}
function set(hh,mm,ss)
{
 h=hh;
 m=mm;
 s=ss;
 timer();
}

function stopTimer()
{
 clearTimeout(t);
}