1

When another input select is changed by option, some things happen and Then a function is called. In this function the price needs to be updated. The problem is that while all of this works, the price is replaced on the last ID. Example: 3 products with prices What happens: the last product is updated 3 times with the prices from all the products.

What I want: each product to be updated to its id (each product / where the price will be replaced has a unique id)

my first php looks like this:

for ($i=0;$i<$myCounter;$i++)
{
echo '<p class="show4 count c'.$i.'" id="a'.$dataReceive[$i]["Detalle"]["IDENDODET"].'">$ '.$currentpricer.'</p>
}

which ends up looking like this:

<p class="show4 count c0" id="a1122">$ 10</p>
<p class="show4 count c1" id="a1123">$ 20</p>

my function looks like this:


function actualizarProduct(){
var nb = $('p.count').length;
var i=0;
for (i = 0; i < nb; i++) {
  var classqq= "c" + i; //get class c0, c1, c2
  var classList = $('.'+classqq).attr('id'); //get id of the class above
  var rClassL = classList.substring(1); //get rid of the "a" in each class

var toreplaceID = "#" + classList; //add # for each id


  $.ajax({
      url: "../datos/elCartPostmanUpdate.php",
      data: {elid:rClassL},
      type: "get",
      dataType:"html",
      success: function(data){
         $(toreplaceID).html(data);
      }
  });
}


}

Lastly, at "/datos/elCartPostmanUpdate.php" reads like this:

$elid1=$_GET['elid'];
$compare = $dataReceive[$i]["Detalle"]["IDENDODET"];
  if ($elid1==$compare){
  echo "$ ".$currentpricer;
}

Like I said, it works, the problem is that the price isn't updated at where it should be updated but instead it only replaces the last product.

0 Answers0