Fix timer starting on page load
A simple Javascript timer that runs for 30 seconds and displays a message once it reaches 0. I cant figure out how to get it to start when a button is pressed instead of on pageload. Any help is appreciated :)

    <script type="text/javascript">
    var sec = 30;   // set the seconds
    var min = 00;   // 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) + " min and " + sec + " sec ";
    if (document.getElementById) { theTime.innerHTML = time; }
      SD=window.setTimeout("countDown();", 1000);
    if (min == '00' && sec == '00') { sec = "00"; window.clearTimeout(SD); alert("Too slow."); }
    }
    
    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();
    });
    </script>
Fix timer starting on page load
===

A simple Javascript timer that runs for 30 seconds and displays a message once it reaches 0. I cant figure out how to get it to start when a button is pressed instead of on pageload. Any help is appreciated :)

    <script type="text/javascript">
    var sec = 30;   // set the seconds
    var min = 00;   // 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) + " min and " + sec + " sec ";
    if (document.getElementById) { theTime.innerHTML = time; }
      SD=window.setTimeout("countDown();", 1000);
    if (min == '00' && sec == '00') { sec = "00"; window.clearTimeout(SD); alert("Too slow."); }
    }
    
    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();
    });
    </script>