Jump to content

countdown function problems in mozilla


ballhogjoni

Recommended Posts

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();
});

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.