Problem with the count up timer in javascript

That’s your PHP code. In post #15, you have some code that looks like JavaScript (based on setTimeout and var and a couple of other things):

timer = setTimeout(gotoNextSlide, $duration * 60000 / $num_questions);

here which uses variables with a similar name, but you don’t seem to define those variables anywhere that I can see. If you want to use the values from your PHP variables inside your JS code, then surely you’d need to use echo to output them in the JS code when the server draws the page, as you did here:

<time id="countdown"><script> var seconds = <?php echo  $duration * 60; ?>;</script>     

If you’re intending the JS code to run from a browser action rather than when initiated by the server re-drawing the page, you’ll need to get the values from the form in your JS code.

I may be out of my depth here, I’m sure someone will be along to comment if I’m made presumptions that aren’t correct. If those are JS variables, I think that while it might be correct to use variable names in JS that start with a $, it just adds confusion to the code.

1 Like