I have the following code:
<h2 id="excTitle">
<div id="titleText">
<?=$exercises[$currentExc]?>
</div>
</h2>
The above code displays a title.
<button type="button" class="styled-button-10b" onClick="skipExc()">Skip</button>
The above code calls the below function, which should change the title.
//Skip to the next exercise
function skipExc()
{
<?php
$currentExc++;
?>
$("#titleText").html('<?php echo $exercises[$currentExc]; ?>');
}
It actually works, but only once.
Let's say I have 5 different titles (5 items in my $exercises array), the code above only go from the first title to the second title and then stops updating.
I have tested and the function is called, but the title doesn't change.
Can anybody please help me with this? Thanks.
<?php echo $exercises[$currentExc]; ?>does not change once the page loads. You can either store$exercisesas a javascript array, and increment through it, or you will need to use ajax to go back to the server/php to get the next value(s)$exercises[$currentExc];was processed in server and returned a single value when it's arriving at the client end.