1

My input field is

<input type="text" id="quantity" value="0" autocomplete="off" size="2" onKeyUp="myfun(this.value,<?php echo $rw['product']?>)">

Here is my ajax code

function myfun(a,b)
{
   var dat = a*<?php echo $rw['amount'] ?>;
   $('#result').html(dat);
   var datas = 'val=' + a + '&id=' + b ;
   if(datas)
   {
      $.ajax({
         type:"POST",
         url:"insert.php",
         data:datas,
         success: function(html){
            $("#result").append(html);
           }
      });
      return false;
   }
}

In insert.page i have the code like below.

$id = $_POST['id'];
if(!isset($_SESSION['QUANTITY'])){
    $_SESSION['QUANTITY']=array();
}
$newdata= array(
        'id' => $id,
        'val' => $val
        );

$_SESSION['QUANTITY'][]=$newdata;
print_r($_SESSION['QUANTITY']);

Every time i hv changed the value in input fied , it should push the data to session array. but it is replacing the values in array rather than append. Please help me to push the values to array every time i changed my value in input field.

angelcool.net
  • 2,505
  • 1
  • 24
  • 26
athira
  • 233
  • 1
  • 4
  • 12

0 Answers0