how to make a unique function for multiple codes of javascript
<p>I have the following code and I am wondering how to put it all on one function and give the id's of the span a unique id. So that way I dont have to have multiple instances off the same code each time. Right now if I want to have 3 countdowns I have to add his code three times and change the span id to a unique ID if i don't it will only work onces. So basically I want to be able to turn the JavaScript into one function so that I can call it without having to copy and paste it multiple times and also be able to have more than one countdown on a page by giving the span its own unique(random) id.</p>

<pre><code>&lt;script&gt;
function showRemaining() {
    &lt;?php echo "var end = new Date('". $row['expires'] ."');"; ?&gt;

    var _second = 1000;
    var _minute = _second * 60;
    var _hour = _minute * 60;
    var _day = _hour *24
    var timer;

    var now = new Date();
    var distance = end - now;
    if (distance &lt; 0 ) {
       clearInterval( timer );
       document.getElementById('countdown').innerHTML = 'EXPIRED!';

       return;
    }
    var days = Math.floor(distance / _day);
    var hours = Math.floor( (distance % _day ) / _hour );
    var minutes = Math.floor( (distance % _hour) / _minute );
    var seconds = Math.floor( (distance % _minute) / _second );

    document.getElementById('countdown').innerHTML = 'Days: ' + days + ' ';
    document.getElementById('countdown').innerHTML += 'Hours: ' + hours + ' ';
    document.getElementById('countdown').innerHTML += 'Minutes: ' + minutes + ' ';
    document.getElementById('countdown').innerHTML += 'Seconds: ' + seconds;

}

timer = setInterval(showRemaining, 1000);
&lt;/script&gt;

&lt;span id="countdown"&gt;&lt;/span&gt;
</code></pre>
