ballhogjoni Posted March 6, 2008 Share Posted March 6, 2008 I decided to post one error at a time. I can probably explain it better. This is my code for a countdown function. My problem is that it works for IE but not mozilla. Can someone point me in the right direction? var sec = 01; // set the seconds var min = 15; // set the minutes function countDown() { sec--; if (sec == -01) { sec = 59; min = min - 1; } else { min = min; } if (sec<=9) { sec = "0" + sec; } time = (min<=9 ? "0" + min : min) + ":" + sec; if (document.getElementById) { theTime.innerHTML = time; } SD=window.setTimeout("countDown();", 1000); if (min == '00' && sec == '00') { sec = "00"; window.clearTimeout(SD); alert("Your Time Has Expired, Order Now or Forever Wonder If You Could be eBay's next Millionaire!."); } } function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { if (oldonload) { oldonload(); } func(); } } } addLoadEvent(function() { countDown(); }); Quote Link to comment Share on other sites More sharing options...
jacksonmj Posted March 7, 2008 Share Posted March 7, 2008 Have you remembered to set the variable theTime? e.g. <div id="timeElem"></div> <script type="text/javascript"> var theTime = document.getElementById("timeElem"); var sec = 01; // set the seconds var min = 15; // set the minutes . . . NB: You're probably better off using setInterval(), and then clearInterval() when the countdown has finished, if you're calling a function repeatedly at uniform intervals. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.