Hi I have a JavaScript for countdown which is selecting time form MySQL and it is working fine on (Chrome, Firefox), but on (IE and Safari) it is returning "NaNd NaNh NaNm NaNs".
I have attached my code below.
<?php
$con = mysqli_connect("localhost", "root", "", "timer") or die("Error Could
not connect to the database Sir." . mysqli_error($con));
$query = mysqli_query($con, "SELECT * FROM counter WHERE id = 1") or
die(mysqli_error($con));
$row = mysqli_fetch_array($query)or die(mysqli_error($con));
?>
<div id="form<?php echo $row['id'];?>" style="color:green" class="form-
group">
</div>
<Script>
function createCountDown(elementId, date){
console.log(date);
// Set the date we're counting down to
var countDownDate = new Date(date).getTime();
console.log(countDownDate);
// Update the count down every 1 second
var x = setInterval(function(){
// Get todays date and time
var now = new Date().getTime();
// Find the distance between now an the count down date
var distance = (countDownDate) - (now);
//Hint on converting from object to the string.
//var distance = Date.parse(countDownDate) - Date.parse(now);
// Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
//console.log(days);
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 *
60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the result in the element with id="demo"
document.getElementById(elementId).innerHTML = days + "d " + hours + "h "
+ minutes + "m " + seconds + "s ";
// If the count down is finished, write some text
if (distance < 0)
{
clearInterval(x);
document.getElementById(elementId).innerHTML = "ORDER EXPIRED";
}
}, 1000);
}
createCountDown("form<?php echo $row['id'];?>", "<?php echo
$row['time_to_expire'] ;?>")
</Script>
Please check if i am missing something again. thank you for all the replies.
createCountDown("form<?php echo $row['id'];?>", "<?php echo $row['time_to_expire'] ;?>")you are using single quote'form<?php echo $row['id'];?>'"<?php echo $row['time_to_expire'] ;?>"because that has to be an integer (will be passed toDate()an IE do not digest string on that. Issue fixed here But that wasn't a single/double combinaison issue.