Javascript Help [Resolved, But I don't know why] in Off Topic
|
|
I'm a mega-newb at javascript. To get straight to the point, the following is not working.
votingtimer.js:
function countDown(){ document.getElementById('countDownText').innerHTML = countDownTime; countDownTime--; setTimeout('countDown()', 1000); }
function startCountDown(){ var timenow = new Date(); var minutes_now = timenow.getMinutes(); if(minutes_end < minutes_now) minutes_end += 60; countDownTime = ((minutes_end*60)+seconds_end)-((minutes_now*60)+timenow.getSeconds()); document.write("Count down text: "+countDownTime+"<br>"); document.write("seconds: "+seconds_end+"<br>"); document.write("minutes:"+minutes_end+"<br>"); document.write("<br /><div id='countDownText' name='countDownText'>") countDown(); }
|
This is the HTML.
<html><head> <title>Vote in Progress</title>
<script language='JavaScript' type='text/javascript'> var countDownTime; var seconds_end = 23; var minutes_end = 32; </script> <script language="JavaScript" src="votingtimer.js"></script>
</head><body disabledLoad='startCountDown()'> <iframe id="votestatus" name="votestatus" style="visibility:hidden;"></iframe> <br> </body></html>
|
No combination of anything I've tried is working. I've tried testing in both IE and Firefox. Another thing, IE regards this as ActiveX. Anyway to avoid that?
[Edit]
If you get rid of the document.write() section, the problem is resolved. I don't why this is, it's just how it's working.
votingtimer.js:
var countDownTime = null var timerID = null
function startTimer() { timeNow = new Date() var minutesNow = timeNow.getMinutes() if(minutesEnd < minutesNow) {minutesEnd += 60} timeNow = new Date() countDownTime = ((minutesEnd*60)+secondsEnd)-((minutesNow*60)+timeNow.getSeconds()) showCountDown() } function showCountDown() { countDownTime -= 1 if (countDownTime <= 0) { stopTimer() alert("Time is up. No more votes will be registered.") } else { document.getElementById("timerDisplay").innerHTML = countDownTime timerID = setTimeout("showCountDown()",1000) } } function stopTimer() { clearTimeout(timerID) document.getElementById("timerDisplay").innerHTML = "Please wait..." }
|
html document:
<html><head><title>Vote in Progress</title>
<script language="javascript" type='text/javascript'> var secondsEnd = 23 var minutesEnd = 32 </script> <script language="javascript" type='text/javascript' src="votingtimer.js"></script>
</head>
<body disabledLoad='startTimer()'>
<iframe id="votestatus" name="votestatus" style="visibility:hidden;"></iframe> <div id='timerDisplay' name='timerDisplay'></div>
</body>
</html>
|
|