egdigital
asked on
Dynamic Javascript timer
I am writing an application using asp.net and want to display a timer on the page. the value that counts down on the time changes so i need a way to pass in a time dynamically into the timer.
if yes, then from the code in the above link the start time is hardcoded to "30"
document.counter.d2.value= '30'
We can dynamically assign values from code-behind using
document.counter.d2.value= '<%=myValu e%>';
and myValue can be set in page_load ..
there are other ways to do the same thing .. that is, passing this value as a parameter to the function, using hidden texboxes etc .. depends on what exactly you are trying to implement
Rejo
document.counter.d2.value=
We can dynamically assign values from code-behind using
document.counter.d2.value=
and myValue can be set in page_load ..
there are other ways to do the same thing .. that is, passing this value as a parameter to the function, using hidden texboxes etc .. depends on what exactly you are trying to implement
Rejo
ASKER
I tried this solution however the timer is not even starting. I think its because I am using an ascx file for this which does not have a form tag. The example here http://java-scripts.net/javascripts/Countdown-Timer.phtml uses form with the name "counter". I have tried the following but the object is still null:
<script type="text/javascript">
<!--
var milisec=0
var seconds=30
document.d2.value='30'
//document.getElementById( "d2").valu e='30'
function display(){
if (milisec<=0){
milisec=9
seconds-=1
}
if (seconds<=-1){
milisec=0
seconds+=1
}
else
milisec-=1
document.d2.value=seconds+ "."+milise c
setTimeout("display()",100 )
}
display()
-->
</script>
<input type="text" size="8" id="d2" name="d2" />
<script type="text/javascript">
<!--
var milisec=0
var seconds=30
document.d2.value='30'
//document.getElementById(
function display(){
if (milisec<=0){
milisec=9
seconds-=1
}
if (seconds<=-1){
milisec=0
seconds+=1
}
else
milisec-=1
document.d2.value=seconds+
setTimeout("display()",100
}
display()
-->
</script>
<input type="text" size="8" id="d2" name="d2" />
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Countdown Timer Javascript
http://java-scripts.net/javascripts/Countdown-Timer.phtml
have a look at the example in the above link
Rejo