Countdown Timer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DennyLoi
    New Member
    • Nov 2007
    • 10

    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.

    [CODE=javascript]//Some other script here^^^^

    var counterForm = document.create Element("form") ;
    counterForm.nam e = "form";
    counterForm.act ion = "";
    var para5 = document.create Element("p");
    var counterInput = document.create Element("input" );
    counterInput.ty pe = "text";
    counterInput.na me = "abc";
    counterInput.id = "abc";
    counterInput.va lue = '';
    counterForm.app endChild(counte rInput);
    para5.appendChi ld(counterForm) ;
    document.body.a ppendChild(para 5);

    } //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.counte rInput.value=se conds+"."+milis ec
    setTimeout("dis play()",100)
    }
    [/CODE]
    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?
    Last edited by gits; Nov 4 '07, 09:55 PM. Reason: added code tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    counterInput is not the name of any form or field.

    Give the form and field ids and then access them using document.geElem entById(theID).

    Comment

    Working...