I'm creating a basic web application project and I'm stuck here: What I am trying to do is to pass javascript variable (which has value of php variable) into jquery code (in external file) from my main .php file.
?>
<script type="text/javascript" src="js/functions.js"></script>
<script type="text/javascript">
correct_answer = "<?php echo $_SESSION["correct_answer"]; ?>";
</script>
<?php
It's working on the first time but since this part of website is also dynamically generated value of "correct_answer" is not refreshed. Is there a way to pass that "new" value into external jquery code?
//reload content of div
$(document).on('click', "#reload_btn", function() {
$("#test_main").load("includes/practise.inc.php #test_main > *");
});
//do something on dynamically added button
$(document).ready(function() {
$(document).on('click', "#yes-btn", function() {
console.log(correct_answer); //here is the problem - it either has the first value or is "undefined"
$("#yes-btn").css( "background-color", "green");
$("#yes-btn").css( "color", "white");
$("#no-btn").css( "background-color", "red");
$("#no-btn").css( "color", "white");
});
});
Thank you in advance!