I can use some help with the following. I would like to change the content of my buttons after pressing the button. Is it possible to change a PHP variable from Javascript, or can I not do this because PHP is server-side?
After that I want to run a MySQL query with this new variable and use it in my while loop. I hope someone can help me.
PHP:
<?php
$result = $conn->query($query_answer);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc())
{
?>
<input type="button" id="<?php echo $row["answer_id"];?>" next_question_id="<?php echo $row["next_question_id"];?>" value="<?php echo $row["answer_text"];?>" onclick=myFunction((this.id));>
<?php
}
}
$conn->close();
?>
JavaScript:
<script>
function myFunction(clicked_id) {
var button = clicked_id
var next_question_id = document.getElementById(button).getAttribute("next_question_id");
$.post ('next_question.php',{postnextquestionid:next_question_id},
function (data)
{
$('#question_text').html(data);
});
}
</script>