I want to convert javascript variable to php variable to use it in sql query,but it doesn't work.
html code :
<select id = "dep_ID" name = "dep_ID" onchange="myFunction()">
javascript code in the same file:
<script>
function myFunction(){
var xo = document.getElementById("dep_ID").value;
document.getElementById("demo").innerHTML = "You selected: " + xo;
$.ajax({
url: 'insert.php',
data: {duration: xo},
type: 'POST',
success: function(data) {
alert(data);
document.getElementById("demo").innerHTML = "You selected: " + <?php echo @$duration;?>;
}
});
}
</script>
insert.php code:
<?php
$duration = $_POST['xo'];
return $duration ;
?>
I expect the output of dep_ID variable, but i get nothing.
$_POST['duration'], not$_POST['xo'].