1

I have 2 page

  • the innerhtml onclick page (a.php)
  • the page that start session (b.php)

in a.php I write function onclick to change some text and I add the session from b.php in this text, but nothing change in text

 $(document).ready(function(){       
      $('.add-to-cart').on('click',function(){

        document.getElementById('outside_cart_text').innerHTML = 
"Qty type <?php echo $this->session->userdata('qty_type'); ?> amount <?php echo $this->session->userdata('qty_product');?>";

            });
        }); 

it change the original text to "Qty type amount". But session value not appear.

the question is how to make it appear instantly?

additional detail : My click is on the button sumbit to other page, but I have already use this trick. It work like ajax. so after click I still in the same page (and not reload)

<style>
  .hide { position:absolute; top:-1px; left:-1px; width:1px; height:1px; }
</style>

<iframe name="hiddenFrame" class="hide"></iframe>

<form action="receiver.pl" method="post" target="hiddenFrame">
  <input name="signed" type="checkbox">
  <input value="Save" type="submit">
</form> 
Supanat T. Boss
  • 305
  • 4
  • 13

2 Answers2

0

Maybe it would work if the variables are encoded in json format.

document.getElementById('outside_cart_text').innerHTML = 
  "Qty type
  <?php echo json_encode($this->session->userdata('qty_type')); ?> 
  amount 
  <?php echo json_encode($this->session->userdata('qty_product'));?>";
});
Felix Chan
  • 13
  • 3
0
$(document).ready(function(){       
    $('.add-to-cart').on('click',function(){
        var qty_type = '<?php echo $this->session->userdata('qty_type'); ?>';
        var amount = '<?php echo $this->session->userdata('qty_product'); ?>';
        $("#outside_cart_text").html("Qty type "+qty_type+" amount "+amount);
    });
}); 
Bhavik
  • 495
  • 2
  • 10