i have been working on my own costum Javascript Countdown for multiple countdowns at the site, but the date doesn't count correctly.
I have this javascript for displaying time counter :
$(function(){
$('.countdown').each(function() {
var $this = $(this),
ts = new Date($this.data('ts')),
newYear = true;
if((new Date()) > ts){
newYear = false;
}
$this.countdown({
timestamp : ts,
callback : function(days, hours, minutes, seconds){
var message = "";
message += days + " hari" + ( days==1 ? '':'' ) + ", ";
message += hours + " jam" + ( hours==1 ? '':'' ) + ", ";
message += minutes + " menit" + ( minutes==1 ? '':'' ) + ", ";
message += seconds + " detik" + ( seconds==1 ? '':'' ) + " <br />";
$this.next().html(message);
}
});
});
});
this is how my table looked :
id | tgl_close1 | idrek
1 | 2014-11-25 08:00:00 | 1
2 | 2014-11-26 10:00:00 | 1
3 | 2014-11-26 12:10:00 | 1
i multiply the countdown by foreach but it always show 'NaN' instead of number :
<?php
$fetch = mysql_query("select tgl_close1
from tba
where idrek = 1");
/* Retrieve and store in array the results of the query.*/
while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)) {
$tgl_close1[] = date("Y, n-1, j, G, i, s", strtotime($row['tgl_close1']));
}
foreach ($tgl_close1 as $tglclose){
?>
<br>
<table border="0"><tr><td>
<div class="countdown" data-ts="<?php echo $tglclose"></div>
<p class="note"></p>
</td></tr></table>
<?php
}
}
mysql_close($conn);
?>
<script type="text/javascript">
$(function(){
$('.countdown').each(function() {
var $this = $(this),
ts = new Date($this.data('ts')),
newYear = true;
if((new Date()) > ts){
newYear = false;
}
$this.countdown({
timestamp : ts,
callback : function(days, hours, minutes, seconds){
var message = "";
message += days + " hari" + ( days==1 ? '':'' ) + ", ";
message += hours + " jam" + ( hours==1 ? '':'' ) + ", ";
message += minutes + " menit" + ( minutes==1 ? '':'' ) + ", ";
message += seconds + " detik" + ( seconds==1 ? '':'' ) + " <br />";
$this.next().html(message);
}
});
});
});
</script>
Can someone tell me what's wrong with my code?
well, i changed my javascript into this :
$(function(){
$('.countdown').each(function() {
var $this = $(this),
ts = new Date($('.note').data('ts')),
newYear = true;
if((new Date()) > ts){
newYear = false;
}
$this.countdown({
timestamp : ts,
callback : function(days, hours, minutes, seconds){
var message = "";
message += days + " hari" + ( days==1 ? '':'' ) + ", ";
message += hours + " jam" + ( hours==1 ? '':'' ) + ", ";
message += minutes + " menit" + ( minutes==1 ? '':'' ) + ", ";
message += seconds + " detik" + ( seconds==1 ? '':'' ) + " <br />";
$this.next().html(message);
}
});
});
});
it get the date passed into javascript,but the $tglclose
that passed into javascript is only the first row, so i have three counter with same time counter..