vendredi 5 octobre 2018

Basic Javascript Timer help needed

What I was going to do is the user will input a number into a text box, then the browser will pop-up an alert that it will countdown ... seconds. Below is my code but nothing seems to working. Please help me. Thanks.

<!DOCTYPE html>
    <html>
        <head> 

        </head>
        <body>
            <script type="text/javascript">
                    function timer(){
                        if(document.getElementById("time").value=="")||(isNaN(document.getElementById("time").value)==true)
                            alert("Please input a number");
                        else
                        alert("Start counting down ",(parseInt(document.getElementById("time").value))/1000," seconds");
                        setTimeout("alert('Times out');",time);
                    }
                </script>

            <input type="text" id="time"/>

            <button onClick="timer();">Submit</button>
        </body>
    </html>

Aucun commentaire:

Enregistrer un commentaire