I have a countdown that I'm trying to get working during onload, but I'm running into issues with closures. Here is my code:
for (var o in myDates) {
var myDate = myDates[o];
var iid = o;
funcs[o] = function() {
var dateFuture = new Date();
dateFuture.setSeconds(dateFuture.getSeconds()+myDate.durationInSecs);
GetCount(dateFuture,iid);
}
myDates[iid].tId = setTimeout("funcs['"+iid+"']()",myDates[o].delay*1000);
}
The above code is not working as expected due to implicit eval and use of global variables. Below is the workaround that does work, but I want to avoid the global vars and make it more efficient:
<html>
<head>
<script type="text/javascript">
// JavaScript code goes here...
</script>
</head>
<body>
<div>
<span id="d0" style="background-color:red">!!</span>
<span style="float:right¨;background-color:green" id="d1">??</span>
</div>
</body>