Iam trying to create a timer using javascript to function the timer and mysqli bound variable $dbSessionDuration to retrieve the start time from the db. Issue is that:
- I am receiving a undefined variable as it states I am
missing ; before statementbut I cannot see where the problem is as it is pointing on the same line as the variable itself
How can I fix the error?
View source code below:
(function(){
$(document).ready(function() {
var time =
Notice: Undefined variable: dbSessionDurationTime in /web/stud/u0867587/Mobile_app/assessment.php on line 108
null,
parts = time.split(':'),
hours = +parts[0],
minutes = +parts[1],
seconds = +parts[2],
span = $('#countdown');
function correctNum(num) {
return (num<10)? ("0"+num):num;
}
var timer = setInterval(function(){
seconds--;
if(seconds == -1) {
seconds = 59;
minutes--;
if(minutes == -1) {
minutes = 59;
hours--;
if(hours==-1) {
alert("timer finished");
clearInterval(timer);
return;
}
}
}
span.text(correctNum(hours) + ":" + correctNum(minutes) + ":" + correctNum(seconds));
}, 1000);
});
});
Actual code below:
(function(){
$(document).ready(function() {
var time = <?php echo json_encode($dbSessionDurationTime); ?>,
parts = time.split(':'),
hours = +parts[0],
minutes = +parts[1],
seconds = +parts[2],
span = $('#countdown');
function correctNum(num) {
return (num<10)? ("0"+num):num;
}
var timer = setInterval(function(){
seconds--;
if(seconds == -1) {
seconds = 59;
minutes--;
if(minutes == -1) {
minutes = 59;
hours--;
if(hours==-1) {
alert("timer finished");
clearInterval(timer);
return;
}
}
}
span.text(correctNum(hours) + ":" + correctNum(minutes) + ":" + correctNum(seconds));
}, 1000);
});
});
$dbSessionDurationTimeisn’t defined. If you go and define that you should no longer receive this error. This is the PHP and not the Java Script.