Advertisement
jamesmva

Untitled

Oct 18th, 2016
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.17 KB | None | 0 0
  1. $(document).ready(function() {
  2.  
  3.   $('.fabric, .size').on('change', sendData);
  4.  
  5.   function sendData() {
  6.    //use the data-id attribute of the selected element to match the correct elements
  7.    var id = $(this).data("id");
  8.     var action = $(this).attr('data-action');
  9.     var fabricID = $('.fabric[data-id=' + id +']').val();
  10.     var sizeID   = $('.size[data-id=' + id +']').val();
  11.     var url = 'checkout.php';
  12.  
  13.     if ( fabricID !== "" && sizeID !== "") {
  14.       $.ajax({
  15.             type     : 'GET',
  16.             url      : 'calculates.php',
  17.             dataType : 'json',
  18.             data     : {
  19.                 prod_id:id,
  20.                 fabric_id: fabricID,
  21.                 action:action,
  22.                 size_id: sizeID
  23.             }
  24.         }).done(function(data) {
  25.           console.log(data);
  26.          
  27.            /*$('.cost[data-id=' + id + ']').html('R$:' + data);
  28.            $('.subtotal[data-id=' + id + ']').html('R$:' + data);*/
  29.           $('.cost[data-id=' + id + ']').html('R$:' + data.cost);
  30.            $('.subtotal[data-id=' + id + ']').html('R$:' + data.subtotal);
  31.            
  32.            
  33.            
  34.            
  35.         });
  36.       }
  37.   }
  38. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement