©ilj@flowsim.se JavaScript code samples 20 JavaScript timer - setTimeout, clearTimeout - timer in text box or in the status bar >>> this example in Swedish ![]() stop! restart! |
![]() code and explanations further down ![]() ![]() ![]() <SCRIPT LANGUAGE="JavaScript" ![]() <!-- startad=0 iljdone=0 function checkstart() { if(startad==0) ![]() ![]() ![]() ![]() ![]() ![]() } i=0 j = 0 function iljtimer4() { if(iljdone<600) { iljtimer = setTimeout("iljtimer4()",1000) if(i<10)i="0"+i window.status =" text: " + j + ":" + i //1 document.iljtimerform2.iljtimerruta3.value =j+ ":"+ i //4 i++ if(i==60) ![]() ![]() ![]() ![]() iljdone++ } } function stoppit() { clearTimeout(iljtimer) startad=0 iljdone=0 } window.onerror = null; //--> </SCRIPT> <FORM NAME = "iljtimerform2"> <INPUT TYPE = "text" ![]() ![]() </FORM> <A HREF = "#" ![]() <A HREF = "#" ![]() ![]() ![]() 2 the name of the FORM 3 the name of the text box 4 this line puts the timer in a text box named iljtimerruta on a FORM named iljtimerform ![]() If you want the timer to start as soon as the page is loaded you can put the call checkstart() after BODY ONLOAD. This timer stops automatically after 10 minutes; change the number after iljdone , (600 in this example) to have it function for shorter or longer period. The following code puts the timer on a div named "iljs" (<div id='iljs'> </div>) if(document.getElementById)i {document.getElementById('iljs').innerHTML=j + ":"+ i} OTHER JAVASCRiPT EXAMPLES ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Page by ![]() ilj@flowsim.se ![]() Last modified: August 17, 1998 This page should be part of a frames system at: http://www.flowsim.se JAVASCRiPT |