By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,451 Members | 981 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,451 IT Pros & Developers. It's quick & easy.

Countdown Timer

P: 10
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
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
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

Post your reply

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