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
- //Some other script here^^^^
- var counterForm = document.createElement("form");
- counterForm.name = "form";
- counterForm.action = "";
- var para5 = document.createElement("p");
- var counterInput = document.createElement("input");
- counterInput.type = "text";
- counterInput.name = "abc";
- counterInput.id = "abc";
- counterInput.value = '';
- counterForm.appendChild(counterInput);
- para5.appendChild(counterForm);
- document.body.appendChild(para5);
- } //closes this function
- var milisec=0 //simple variables
- var seconds=10
- function display(){
- if (milisec<=0){
- milisec=9
- seconds-=1
- }
- if (seconds<=-1){
- milisec=0
- seconds+=1
- }
- else {
- milisec-=1
- document.counterInput.value=seconds+"."+milisec
- setTimeout("display()",100)
- }
[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?