Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I got two dropdowns in each product in my cart.

look my UI


When i select my both option my class on success is not updating the cost. It only updates when i refresh the page, i dont want to refresh my page to get the cost.

What I have tried:

JavaScript
$(document).ready(function() {
  $('.fabric, .size').on('change', sendData);
  function sendData() {
  var id = $(this).data("id");
  var fabricID = $('.fabric[data-id=' + id +']').val(); 
  var sizeID   = $('.size[data-id=' + id +']').val();
    if ( fabricID !== "" && sizeID !== "") {
      $.ajax({
            type     : 'GET',
            url      : 'calculates.php',
            dataType : 'json',
            data     : {
                prod_id:id,
                fabric_id: fabricID,
                size_id: sizeID
            }
        }).done(function(data) {
            $('.cost' + id).text(data.val);
            $('.subtotal' + id).load(data.val);
         });
      }
  }
});


this is where i am trying to update when user select his product options

HTML
'.$value.' R$: '.$_SESSION['icms'.$id].' R$: '.$value * $_SESSION['icms'.$id] .'>

My $value holds the quantity of my product. And other problem that i'm getting is when i click in my plus and remove button,i don't get my subtotal to updated either.

And this script handles my $value to keep updating when i click on my button.

<pre lang="JavaScript">$('.actions').click(function(e){
  e.preventDefault();
  var action = $(this).attr('data-action'); 
  var id = $(this).attr('product_id');
  var cost_id = $(this).data("id");
  console.log("triggered action " + action + " for product " + id); //debugging
  $.ajax({
    url: 'cart_functions.php',
    type : 'GET',
    data: {action:action,prod_id:id},
    dataType: 'json',
    success: function(data)
    {
      console.log("ajax call returned the following: " + JSON.stringify(data)); //debugging
      if (data.result == "success") {
        if (action == "plus" || action == "remove")
        {
          console.log("identified product td for " + id + ": " + $(".product" + id).length); //debugging
          $(".product" + id).text(data.val);
          $(".subtotal" + cost_id).text(data.val);
          //update the UI with the new total
        }

So as you can see i used in both scripts my class subtotal. So it can update when i click in my plus or remove button and on dropdown selection changes the subtotal and the cost for each product. Why my jquery is not updating my cost and subtotal?
Im still a noob at jquery. Please some help.
Posted
Comments
ZurdoDev 12-Oct-16 6:58am    
Put a breakpoint and debug it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900