Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Countdown Timer

I need a count down timer that can display second:miliseconds format, I found one that I figured I could modify it to show this like 4:92 but it doesn't want to work for me for some reason. It works fine on the site, but I try and put it into my page, the console tells me:

Uncaught ReferenceError: display is not defined.

What did I do wrong?

    var milisec=0 
    var seconds=30 
    document.getElementById("timer").innerHTML='30' 
    function display(){ 
        if (milisec<=0){ 
            milisec=9 
            seconds-=1 
        } 
        if (seconds<=-1){ 
            milisec=0 
            seconds+=1 
        } 
        else 
            milisec-=1 
            document.getElementById("timer").innerHTML=seconds+"."+milisec 
            setTimeout("display()",100) 
    } 
display() 

(original source)

like image 460
Sean Avatar asked Oct 14 '22 17:10

Sean


1 Answers

Make it setTimeout( display, 100 ) so the literal is passed, otherwise it executes in global context and most likely that fn is not defined as a method of window ( maybe because you have it a window load anon literal? )

like image 193
meder omuraliev Avatar answered Dec 04 '22 00:12

meder omuraliev