jeudi 12 février 2015

Timer not displaying on HTML page


I am trying to get a countdown timer to load when the body of my HTML page loads. I have the following code in HTML and Javascript and I need help making the timer actually display on my page. Any ideas?





<script>
var Timer;
var TotalSeconds;


function CreateTimer(TimerID, Time) {
Timer = document.getElementById(TimerID);
TotalSeconds = Time;

UpdateTimer()
window.setTimeout("Tick()", 100);
}

function Tick() {
if (TotalSeconds <= 0) {
alert("Time's up!")
return;
}

TotalSeconds -= 1;
UpdateTimer()
window.setTimeout("Tick()", 100);
}

function UpdateTimer() {
Timer.innerHTML = TotalSeconds;
}



<!DOCTYPE html>
<html>
<head>
<title>50 States</title>
<link rel="stylesheet" href="./Styles/Lab2.css"></head>

<h1>50 States</h1>
<h3>Enter state to start timer</h3>

<body onload="CreateTimer("timer", 6000)";>

<script src="Lab2.js"></script>

<form>
<input type="text" id="text_box_1" value="" autofocus onkeyup="doSomething()" onkeypress="searchKeyPress(e)" >
<input type="submit" id="button_1" value="Enter" onClick="doSomething()"/>

</form>
<div id="timer" value=""/>
<div id="answer"value=""/>

</body>
</html>






Aucun commentaire:

Enregistrer un commentaire