java script timer control
-
hi folks, I wud like to display running time in my page using javascript.For that i ve used the following client side function. <form name="counter"><input type="text" size="8" name="d2"></form> <script type="text/javascript"> var milisec=0 var seconds=120 // document.counter.d2.value=0 function display() { if (milisec<=0){ milisec=9 seconds-=1 } if (seconds<=-1) { milisec=0 seconds+=1 } else milisec-=1 document.counter.d2.value=seconds+"."+milisec setTimeout("display()",1000) } display() ive hardcoded it as 120 seconds.But i need to pass a value from code behind dynamically and make the timer run for that value. for e.g i want to pass as display(180) and run the timer.Is there any way of achieving this?Advance thanx
T.Balaji
-
hi folks, I wud like to display running time in my page using javascript.For that i ve used the following client side function. <form name="counter"><input type="text" size="8" name="d2"></form> <script type="text/javascript"> var milisec=0 var seconds=120 // document.counter.d2.value=0 function display() { if (milisec<=0){ milisec=9 seconds-=1 } if (seconds<=-1) { milisec=0 seconds+=1 } else milisec-=1 document.counter.d2.value=seconds+"."+milisec setTimeout("display()",1000) } display() ive hardcoded it as 120 seconds.But i need to pass a value from code behind dynamically and make the timer run for that value. for e.g i want to pass as display(180) and run the timer.Is there any way of achieving this?Advance thanx
T.Balaji
-
hi folks, I wud like to display running time in my page using javascript.For that i ve used the following client side function. <form name="counter"><input type="text" size="8" name="d2"></form> <script type="text/javascript"> var milisec=0 var seconds=120 // document.counter.d2.value=0 function display() { if (milisec<=0){ milisec=9 seconds-=1 } if (seconds<=-1) { milisec=0 seconds+=1 } else milisec-=1 document.counter.d2.value=seconds+"."+milisec setTimeout("display()",1000) } display() ive hardcoded it as 120 seconds.But i need to pass a value from code behind dynamically and make the timer run for that value. for e.g i want to pass as display(180) and run the timer.Is there any way of achieving this?Advance thanx
T.Balaji
Hi Balaji, Use RegisterClientVariable, you may refer to the following code snippet:
At Server Side: ClientScript.RegisterHiddenField("HiddenField", "120");
At Client Side: var temp = document.getElementById("HiddenField");
I hope this would be helpful.John Adams ComponentOne LLC. www.componentone.com