[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Dynamic Javascript timer

Posted on 2007-10-09
4
Medium Priority
?
557 Views
Last Modified: 2012-05-05
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.
0
Comment
Question by:egdigital
  • 3
4 Comments
 
LVL 26

Expert Comment

by:Rejojohny
ID: 20041613
is this what you want?

Countdown Timer Javascript
http://java-scripts.net/javascripts/Countdown-Timer.phtml

have a look at the example in the above link

Rejo
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 20041646
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='<%=myValue%>';

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


0
 

Author Comment

by:egdigital
ID: 20042312
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").value='30'

function display(){
 if (milisec<=0){
    milisec=9
    seconds-=1
 }
 if (seconds<=-1){
    milisec=0
    seconds+=1
 }
 else
    milisec-=1
    document.d2.value=seconds+"."+milisec
    setTimeout("display()",100)
}
display()
-->
</script>

<input type="text" size="8" id="d2" name="d2" />

0
 
LVL 26

Accepted Solution

by:
Rejojohny earned 2000 total points
ID: 20051059
document.getElementById('d2').value='30';
is not working?

do not that you need semi-colons ";" at the end of each line in javascript
and strings have to enclosed in single quotes and not double quotes .. ('d2')

try this
<script type="text/javascript">
<!--
var milisec=0;
var seconds=30 ;
document.getElementById('d2').value='30';

function display()
{
 if (milisec<=0)
{
    milisec=9;
    seconds-=1;
 }
 if (seconds<=-1)
{
    milisec=0;
    seconds+=1;
 }
 else
{
    milisec-=1;
}
 
  document.d2.value=seconds+"."+milisec ;
    setTimeout("display()",100) ;
}
display() ;
-->
</script>

<input type="text" size="8" id="d2" name="d2" />
0

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question