Reputation: 139
<script language="javascript">
function emergency()
{
if(document.getElementById('emer').checked == true)
{
<?php $_SESSION['total2']= $_SESSION['total1'] + 50; ?>
document.getElementById('emr').innerHTML = "<b>Payable Amount: </b>" + <?php echo $_SESSION['total2']; ?>;
}
if(document.getElementById('emer').checked == false)
{
<?php $_SESSION['total2']= $_SESSION['total2'] - 50; ?>
document.getElementById('emr').innerHTML = "<b>Payable Amount: </b>" + <?php echo $_SESSION['total2']; ?>;
}
}
</script>
here I am adding $_SESSION['total1']+50
and put the value in new session SESSION['total2']
. The problem is that , when I echo this new $_SESSION['total2']
out side script,ie, in the page like
<?php echo $_SESSION['total2'];?>
it returns the value of $_SESSION['total1']).
Upvotes: 1
Views: 1292
Reputation: 2128
Are you calling a javascript function to change value of php session variable?.. this could not be possible because, php is a server side language and javascript is client side so php code gets executed when the page is loaded..
so if you want to do this on javascript function call,, than you need to use ajax
...
Upvotes: 4
Reputation: 1357
to get the new value of $_SESSION['total2']
you have to run the code on server side again. that means before getting the new value for total2 session variable you have to reload the appropriate php file.
Upvotes: 1