ID:183764
 
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--;
//UpdateScores();
//if(countDownTime <= 0) {
// document.getElementById('countDownText').innerText = "Please wait...";
// return;
//}
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>
Open it in Firefox and see if there are any errors listed in the console (Tools -> Error Console, on FF 2.0).
In response to Crispy (#1)
You probably opened it in notepad, and saved it as a text document instead of a js file. It worked for me in FF.
In response to Crispy (#1)
I never knew about that. Thanks. :D

It says that countDown is not defined. This is on the line in countDown that says setTimeOut("countDown", 1000).
Using anything in setTimeout is not working for me. I don't know what the problem is.
In response to CaptFalcon33035 (#4)
Create a new file in notepad, save it as votingtimer.js under all files.
In response to Xx Dark Wizard xX (#5)
What's the point? I already have votingtimer.js and deleting it to save a file with the same name would be useless. Besides, if you think I've got it under .txt, well... I don't. It's calling startCountDown() onLoad, isn't it?
In response to CaptFalcon33035 (#6)
I made a javascript file, not as txt file. And I get these results.
Count down text: 3199
seconds: 23
minutes:92

3199
In response to Xx Dark Wizard xX (#7)
3199 should start counting down. If you check your Error Console, it should give an error about countDown() being undefined. I hate recursive loops.