multiple records using the same script
<p>I have built a voucher website, where each voucher has a countdown timer. When you view a voucher the countdown works fine, however...
I also have a summary page with multiple vouchers (using a repeat region on the recordset)... when I apply the script to each of the vouchers the script doesn't work.</p>

<p>The HMTL:</p>

<pre><code>      &lt;h3 class="remaining"&gt;&lt;?php echo $row_rs_dealItem['dateend']; ?&gt; remaining&lt;/h3&gt;
</code></pre>

<p>The JAVASCRIPT external file:</p>

<pre><code>$(document).ready(function(){
$('.remaining').each(function(){
    var expiry_date = Date.createFromMysql($(this).html());
    var current_date = new Date();
    console.log(expiry_date.getTime() );
    console.log(current_date.getTime());
    if (expiry_date.getTime() &gt;  current_date.getTime()) {
        var time_diff = Math.floor((expiry_date.getTime() - current_date.getTime()) / (1000*60*60));
        console.log(expiry_date.getTime() - current_date.getTime());
        console.log(time_diff);
        days_diff = Math.floor(time_diff / 24);
        hours_diff = time_diff % 24;

        $(this).html(days_diff + ' days ' + hours_diff + ' hours');
    }
    else{
        $(this).html('expired');
    }
});
}); 

 Date.createFromMysql = function(mysql_string)
{ 
 if(typeof mysql_string === 'string')
{
   var t = mysql_string.split(/[- :]/);

  //when t[3], t[4] and t[5] are missing they defaults to zero
  return new Date(t[0], t[1] - 1, t[2], t[3] || 0, t[4] || 0, t[5] || 0);          
}

return null;   
}
</code></pre>

<p>The JAVASCRIPT inline:</p>

<pre><code>    &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="scripts/script.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
    var reference       = '&lt;?php echo $row_rs_dealItem['reference']; ?&gt;';
    var today           = Date.createFromMysql('&lt;?php echo date('Y-m-d h:i:s'); ?&gt;');
    var contractstarts  = &lt;?php echo ($row_rs_dealItem['datestart'] == '0000-00-00') ? '""' : 'Date.createFromMysql("' . $row_rs_dealItem['datestart'] . '")'; ?&gt;;
    var contractexpires = &lt;?php echo ($row_rs_dealItem['dateend'] == '0000-00-00') ? '""' : 'Date.createFromMysql("' . $row_rs_dealItem['dateend'] . '")'; ?&gt;;
&lt;/script&gt;
</code></pre>

<p>I hope this is enough data for you.</p>

<p>thanks</p>
