I want a countdown on my website that starts with a value from php (out of a MySQL database).
Currently I use the following function:
<script type="text/javascript">
var seconds;
var temp;
var tijd = <? echo json_encode($t); ?>
function countdown() {
seconds = document.getElementById('countdown').innerHTML;
seconds = parseInt(seconds, tijd);
if (seconds == 1) {
temp = document.getElementById('countdown');
temp.innerHTML = "0";
return;
}
seconds--;
temp = document.getElementById('countdown');
temp.innerHTML = seconds;
timeoutMyOswego = setTimeout(countdown, 1000);
}
countdown();
</script>
But in case $t is not 10 the value is increasing with strange steps. How can I solve this? I don't have experience with javascript, so that's the problem.
Besides that, when I adding this script, the following code:
header('Content-Type: text/html; charset=iso-8859-1');
isn't working anymore, because for example " ë " is represented with a ? in the text. I don't know why this is happening?
Who can helps me? Thanks in advance.
<meta charset="UTF-8">