Javascript function not working properly
<p>Ok, so i've got the following javascript on my website to countdown timer:</p>

<pre><code>&lt;script type="text/javascript"&gt;
function timer(elementid, totaltime, format, color, style, trigger_a, trigger_b, done) {

  var hours = 0; var minutes = 0; var seconds = 0;

  if (totaltime &gt; 0) {

    while (totaltime &gt;= 3600) { hours++; totaltime -= 3600; }
    if (hours &lt; 10) { hours = '0' + hours; }
    while (totaltime &gt;= 60) { minutes++; totaltime -= 60; }
    if (minutes &lt; 10) { minutes = '0' + minutes; }
    seconds = totaltime;
  }

  function display() {

    if (hours == 0 &amp;&amp; minutes == 0 &amp;&amp; seconds == 0) {

      if (trigger_a == "reload") { location.href="page.php"; }
      else if (trigger_a == "enable" &amp;&amp; trigger_b != "") { document.getElementById(trigger_b).disabled = false; }
      else { /* do nothing */ }

      document.getElementById(elementid).innerHTML = done;      
    }

    else {

      var output = '';

      if (seconds &gt; 0 &amp;&amp; seconds &lt;= 59) { seconds--; if (hours &lt; 10) { hours = '0' + hours; } }
      else {
        if (minutes &gt; 0 &amp;&amp; minutes &lt;= 59) { minutes--; if (minutes &lt; 10) { minutes = '0' + minutes; } }
        else {
          if (hours &gt; 0) { hours--; minutes = 59; }
        }
        seconds = 59;
      }

      if (hours &gt; 0) {        
        if (format == 'long') { output += hours + " hours "; }
        else if (format == 'small') { output += hours + "h "; }
      }

      if (minutes &gt; 0) {       
        if (format == 'long') { output += minutes + " minutes "; }
        else if (format == 'small') { output += minutes + 'm ';}
      }

      if (seconds &lt; 10) { seconds = '0' + seconds; }
      if (format == 'long') { output += seconds + ' seconds'; }
      else if (format == 'small') { output += seconds + 's'; }

      if (color == '') {

        if (style == 'bold') { document.getElementById(elementid).innerHTML = '&lt;b&gt;' + output + '&lt;/b&gt;'; }
        else { document.getElementById(elementid).innerHTML = output; }
      }

      else {

        if (style == 'bold') { document.getElementById(elementid).innerHTML = '&lt;font color='+color+'&gt;&lt;b&gt;' + output + '&lt;/b&gt;&lt;/font&gt;'; }
        else { document.getElementById(elementid).innerHTML = '&lt;font color='+color+'&gt;' + output + '&lt;/font&gt;'; }
      }      
      setTimeout(display, 1000);
    }
  }
  display();  
}
&lt;/script&gt;
</code></pre>

<p>I add a span box like this:</p>

<pre><code>&lt;?php
$time_left = $from_database['time_left']; //timestamp;
?&gt;
&lt;span id="test"&gt;&lt;/span&gt;
&lt;script&gt;
timer("test", "&lt;?php echo $time_left - Time(); ?&gt;", "long", "", "", "enable", "unlock_this", "Done");
&lt;/script&gt;

&lt;input type="submit" id="unlock_this" &lt;?php if ($time_left - Time() &gt; 0) { echo 'disabled'; } ?&gt; /&gt;
</code></pre>

<p>The problem is, that when I refresh this page (after $time_left), the 'Done' message is not being displayed and I get a javascript error (document.getElementById = null) which directs back to </p>

<pre><code>else if (trigger_a == "enable" &amp;&amp; trigger_b != "") { document.getElementById(trigger_b).disabled = false; }
</code></pre>

<p>It's probably just a little thing, but i can't figure out what i've done wrong, so please help.</p>
