473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Countdown Timer

Hi everyone.

I am trying to implement a countdown timer which is displayed on my page. The counter needs to countdown from 10 seconds to 0 upon the page loading up.

I tried the following, but am running into difficulties.

Expand|Select|Wrap|Line Numbers
  1. //Some other script here^^^^
  2.  
  3. var counterForm = document.createElement("form");
  4.     counterForm.name = "form";
  5.       counterForm.action = "";
  6.        var para5 = document.createElement("p");
  7.        var counterInput = document.createElement("input");
  8.     counterInput.type = "text";
  9.       counterInput.name = "abc";
  10.       counterInput.id = "abc";
  11.       counterInput.value = '';
  12.       counterForm.appendChild(counterInput);
  13.     para5.appendChild(counterForm);
  14.       document.body.appendChild(para5);
  15.  
  16.     }        //closes this function
  17.  
  18.     var milisec=0         //simple variables
  19.     var seconds=10 
  20.     function display(){ 
  21.     if (milisec<=0){ 
  22.     milisec=9 
  23.     seconds-=1 
  24.     } 
  25.     if (seconds<=-1){ 
  26.     milisec=0 
  27.     seconds+=1 
  28.     } 
  29.     else {
  30.     milisec-=1 
  31.     document.counterInput.value=seconds+"."+milisec 
  32.     setTimeout("display()",100) 
  33.     }
  34.  
The first part of the code is I snippet of function start() which is called as follows:

[HTML]<body onload="start()">
</body>[/HTML]

The error I’m being given is “counterInput is not defined”.

I had this script working as a separate page, but when I tried adding into my work, the problems started.

Any suggestions?
Nov 4 '07 #1
1 3522
acoder
16,027 Expert Mod 8TB
counterInput is not the name of any form or field.

Give the form and field ids and then access them using document.geElementById(theID).
Nov 5 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Bonnett | last post by:
I have been creating a generic countdown timer (source code below), counting the seconds, minutes, hours and days till an event, but I have having trouble with it finding out how many hours are...
4
by: Christine | last post by:
I've implemented a countdown timer for a tutorial web page that should give the user 45 minutes to complete the test, only to find that the timer is slowly 'losing' time. On average, it actually...
8
by: Michael | last post by:
I have this script that works the way I want except for one thing... Once it hits zero it starts to count up and looks like this: -1:0-1:0-1:0-18 with the last number counting up. Can anyone...
1
by: Will | last post by:
I have form showing instructions and logging actions and I would like the form to show a count down timer for a certain period of time. E.g. 30 secs, going down to 0 and then displaying the action....
3
by: JimJam | last post by:
Hello Peeps I have created a program in VB.NET 2003 that counts down from 7.5 hours to zero from 08:00. I have a button that starts a new countdown from 1 hour to zero whilst the first one is...
1
by: Dirk Hagemann | last post by:
Hi! I'd like to implement a countdown timer on a webite. It should show the months, days, hours, minutes and seconds until a given date and time. So far it's not really difficult, but this...
9
by: Yet Another One | last post by:
Sorry if this has been answered before, but I simply cannot find the solution on my own. I am looking to do a countdown in my application. Basically, I need to count down from 5:59 (5 minutes,...
9
by: MC | last post by:
I would like to display a timer in the corner of the page that shows the user how many minutes:seconds till the session times out. Are there any good examples out there? Google has again failed...
5
mageswar005
by: mageswar005 | last post by:
hi, I need a javascript countdown timer to my website, I have already the countdown timer but its have some problem. Note: 1) If i choose the tools/internet option in my browser means , at...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.