According to the main acceptance of the title, how do you explain the following:
...
$temp1=$_POST['expert_id']; ?>
<script type="text/javascript">
var jstemp1 =<?php echo json_encode($temp1); ?>;
</script>
<?php
$temp1=$_POST['answers_id']; ?>
<script type="text/javascript">
var jstemp2 =<?php echo json_encode($temp1); ?>;
</script>
Suppose $_POST['expert_id']=1 and $_POST['answers_id']=2. My thought is that $temp1 will equal to 2 when Javascript code begins to execute since PHP code executes first. Therefore, jstemp1 would equal to 2 and jstemp2 would equal to 2. However, to my big surprise, jstemp1=1 and jstemp2=2. Can you explain that to me?
$temp1from$_POST['expert_id'](presumably 1) to$_POST['answers_id'](presumably 2).echo <script type... blah blah blah> ... </script>you're still pushing the code to the output buffer (screen) but the JS won't be executed as it's output (same as with just loading an normal HTML page)