2016-04-14 15 views
0

商品の追加と削除のためのカート内のjquery-codeはこちらです。しかし、それは量を変えず、私が得ているもう一つのエラーはカートに追加した後で2つのアイテムの量を示しています。例:商品の価格が$ 45の場合、それは私に$ 90を示します。カートの商品の加減算が正しく機能していない

これは非常に高い評価を受けています。

<tbody> 
    <tr id="product_1338_19903_0_0" class="cart_item last_item first_item address_0 odd"> 

    <td class="ct-wishList-image"> 
     <img style="width:100px;" src="admin/itempics/<?php echo $row['itemno']?>.jpg" alt="<?php echo $row['model_name']?>"> 
    </td> 
    <td class="ct-wishList-description"> 
     <p class="boughItemId"> 
     <?php echo $row[ 'itemno']; ?> 
     </p> 
    </td> 
    <td class="ct-wishList-description"> 
     <p class="product-name"> 
     <a href=""> 
      <?php echo $row[ 'model_name']?> 
     </a> 
     </p> 
    </td> 
    <td class="ct-wishList-price"> 
     <?php echo $row[ 'price'] ?>,00 kr</td> 
    <td class="cart_quantity text-center"> 
     <input class="itemBoughtQty" type='text' name='qty<?php echo $items_id; ?>' size="2" id='qty<?php echo $items_id; ?>' value="1" /> 
     </br> 
     <input type='button' onclick="subchange<?php echo $items_id; ?>()" name='subtract' value='-' /> 
     <input type='button' onclick="addchange<?php echo $items_id; ?>()" name='add' value='+' /> 
     <script> 
     $(function() { 
      var nTotalCount = 0; 
      var szUrlString = "index.php?con=6&itemid="; 

      $("span[itempricetag='1'").each(function(tag) { 
      nTotalCount = Number($(this).html()) + Number(nTotalCount); 

      }); 
      $(".boughItemId").each(function(tag) { 
      szUrlString += $(this).html() + ","; 
      }); 

      szUrlString += "&qty="; 
      $(".itemBoughtQty").each(function(tag) { 
      szUrlString += $(this).val() + ","; 
      }); 
      $("#total_price").html(nTotalCount); 
      $("#cart_price").html(nTotalCount); 
      $("#cart_total").html(nTotalCount); 
      $("#total_total").html(nTotalCount); 
      $("#ptcl").attr("href", szUrlString + "&total=" + nTotalCount); 
     }); 
     //document.getElementById("total_price").innerHTML= $total; 
     function addchange <?php echo $items_id; ?>() { 
      $item_value = document.getElementById("qty<?php echo $items_id; ?>").value++; 
      document.getElementById("total_product_price_1338_19903_0<?php echo $items_id; ?>").innerHTML = ($item_value + 1) * <? php echo $row['price'] ?> ; 

      //total_price 
      var nTotalCount = 0; 
      var szUrlString = "index.php?con=6&itemid="; 
      $("span[itempricetag='1'").each(function(tag) { 
      nTotalCount = Number($(this).html()) + Number(nTotalCount); 
      }); 

      $(".boughItemId").each(function(tag) { 
      szUrlString += $(this).html() + ","; 
      }); 
      szUrlString += "&qty="; 
      $(".itemBoughtQty").each(function(tag) { 
      szUrlString += $(this).val() + ","; 
      }); 
      $("#total_price").html(nTotalCount); 
      $("#cart_price").html(nTotalCount); 
      $("#cart_total").html(nTotalCount); 
      $("#total_total").html(nTotalCount); 
      $("#ptcl").attr("href", szUrlString + "&total=" + nTotalCount); 
     } 

     function subchange <? php echo $items_id; ?>() { 
      $item_count = document.getElementById("qty<?php echo $items_id; ?>").value; 
      if ($item_count > 1) { 
      $item_value = document.getElementById("qty<?php echo $items_id; ?>").value--; 
      document.getElementById("total_product_price_1338_19903_0<?php echo $items_id; ?>").innerHTML = ($item_value - 1) * <? php echo $row['price'] ?> ; 
      var nTotalCount = 0; 
      $("span[itempricetag='1'").each(function(tag) { 
       nTotalCount = Number($(this).html()) + Number(nTotalCount); 
      }); 
      $("#total_price").html(nTotalCount); 
      $("#cart_price").html(nTotalCount); 
      $("#cart_total").html(nTotalCount); 
      $("#total_total").html(nTotalCount); 
      $("#ptcl").attr("href", "index.php?con=6&total=" + nTotalCount); 
      } 
     } 
     </script> 
    </td> 
    <td id="cart_total" data-title="Total"> 
     <span itempricetag="1" class="cart_total" id="total_product_price_1338_19903_0<?php echo $items_id; ?>"> <?php echo $row['price'] ; ?> </span> 
     <td class="ct-wishList-button"> 
     <a class="btn btn-default btn-md del_item<?php echo $items_id; ?>" data-value="<?php echo $key; ?>">X</a> 
     <script> 
      $(".del_item<?php echo $items_id; ?>").click(function() { 
      var delcartvalue = $(this).data('value'); 
      //alert(delcartvalue); 
      $.ajax({ 
       type: "GET", 
       url: "cancel_item.php", 
       data: { 
       cancelitem: delcartvalue 
       }, 
      }); 
      $(this).closest('tr').fadeOut(); 
      window.location.reload(); 
      }); 
     </script> 
     </td> 

    </tr> 

</tbody> 
+0

あなたの$ item_countチェックは> = 1ですか? 1は有効な数のアイテムでもあります。 –

+0

私はカートで最小値を1にして、顧客はそれを0に減らしません。 –

+0

そのような関数名に変数を入れる必要はありません。変数は関数に渡す必要があります。とにかく、あなたの関数名の関数 'addchange <? PHPエコー$ items_id; ?>(){'。 – larsAnders

答えて

0

 <td class="ct-wishList-image"> 
      <img style="width:100px;" src="admin/itempics/<?php echo $row['itemno']?>.jpg" alt="<?php echo $row['model_name']?>"> 
     </td> 
     <td class="ct-wishList-description"> 
      <p class="boughItemId"> 
      <?php echo $row[ 'itemno']; ?> 
      </p> 
     </td> 
     <td class="ct-wishList-description"> 
      <p class="product-name"> 
      <a href=""> 
       <?php echo $row[ 'model_name']?> 
      </a> 
      </p> 
     </td> 
     <td class="ct-wishList-price"> 
      <?=$row['price'] ?>,00 kr 
      </td> 
     <td class="cart_quantity text-center"> 
      <input class="itemBoughtQty" type='text' name='qty<?php echo $items_id; ?>' size="2" id='qty<?php echo $items_id; ?>' value="1" /> 
      </br> 
      <input type='button' onclick="subchange(<?php echo $items_id; ?>)" name='subtract' value='-' /><? /*subchange<?php echo $items_id; ?>()*/ ?> 
      <input type='button' onclick="addchange(<?php echo $items_id; ?>,<?php echo $row['price']; ?>)" name='add' value='+' /><? /*subchange<?php echo $items_id; ?>()*/ ?> 
     <script> 
      $(function() { 
       var nTotalCount = 0; 
       var szUrlString = "index.php?con=6&itemid="; 

       $("span[itempricetag='1'").each(function(tag) { 
       nTotalCount = Number($(this).html()) + Number(nTotalCount); 

       }); 
       $(".boughItemId").each(function(tag) { 
       szUrlString += $(this).html() + ","; 
       }); 

       szUrlString += "&qty="; 
       $(".itemBoughtQty").each(function(tag) { 
       szUrlString += $(this).val() + ","; 
       }); 
       $("#total_price").html(nTotalCount); 
       $("#cart_price").html(nTotalCount); 
       $("#cart_total").html(nTotalCount); 
       $("#total_total").html(nTotalCount); 
       $("#ptcl").attr("href", szUrlString + "&total=" + nTotalCount); 
      }); 
      //document.getElementById("total_price").innerHTML= $total; 
      function addchange (item_id , price) { // <-here add item_id , price 
       var item_value = document.getElementById("qty"+item_id).value;// change var item_value = document.getElementById("qty"+item_id).value++; 
       document.getElementById("qty"+item_id).value = Number(item_value)+1;// add 

       document.getElementById("total_product_price_1338_19903_0"+item_id).innerHTML = (Number(item_value)+1) * Number(price) ; 
       // change "total_product_price_1338_19903_0"+item_id 
       // (Number(item_value)+1) * Number(price) 

       //total_price 
       var nTotalCount = 0; 
       var szUrlString = "index.php?con=6&itemid="; 
       $("span[itempricetag='1'").each(function(tag) { 
       nTotalCount = Number($(this).html()) + Number(nTotalCount); 
       }); 

       $(".boughItemId").each(function(tag) { 
       szUrlString += $(this).html() + ","; 
       }); 
       szUrlString += "&qty="; 
       $(".itemBoughtQty").each(function(tag) { 
       szUrlString += $(this).val() + ","; 
       }); 
       $("#total_price").html(nTotalCount); 
       $("#cart_price").html(nTotalCount); 
       $("#cart_total").html(nTotalCount); 
       $("#total_total").html(nTotalCount); 
       $("#ptcl").attr("href", szUrlString + "&total=" + nTotalCount); 
      } 

      function subchange(item_id) { 
       var item_count = document.getElementById("qty"+item_id).value; 
       var price = "<?=$row['price'] ?>"; 
       if (item_count > 1) { 
       document.getElementById("qty"+item_id).value = Number(item_count)-1; 
       document.getElementById("total_product_price_1338_19903_0"+item_id).innerHTML = (Number(item_count)-1) * Number(price) ; 
       var nTotalCount = 0; 
       $("span[itempricetag='1'").each(function(tag) { 
        nTotalCount = Number($(this).html()) + Number(nTotalCount); 
       }); 
       $("#total_price").html(nTotalCount); 
       $("#cart_price").html(nTotalCount); 
       $("#cart_total").html(nTotalCount); 
       $("#total_total").html(nTotalCount); 
       $("#ptcl").attr("href", "index.php?con=6&total=" + nTotalCount); 
       } 
      } 
      </script> 

     </td> 
     <td id="cart_total" data-title="Total"> 
      <span itempricetag="1" class="cart_total" id="total_product_price_1338_19903_0<?php echo $items_id; ?>"> <?php echo $row['price'] ; ?> </span> 
      <td class="ct-wishList-button"> 
      <a class="btn btn-default btn-md del_item<?php echo $items_id; ?>" data-value="<?php echo $key; ?>">X</a> 
      <script> 
       $(".del_item<?php echo $items_id; ?>").click(function() { 
       var delcartvalue = $(this).data('value'); 
       //alert(delcartvalue); 
       $.ajax({ 
        type: "GET", 
        url: "cancel_item.php", 
        data: { 
        cancelitem: delcartvalue 
        }, 
       }); 
       $(this).closest('tr').fadeOut(); 
       window.location.reload(); 
       }); 
      </script> 
      </td> 

     </tr> 

+0

あなたは何か変更しましたか?それは何ですか... –

+0

変更コード 続きを読む –

+0

商品を追加すると同じエラーが発生します2個の商品の価格が表示されます。 –

0

<html> 
 
    <head> 
 
     <meta http-equiv="content-type" content="text/html; charset=euc-kr"> 
 
     <title>test</title> 
 
     <script src="https://code.jquery.com/jquery-1.12.0.min.js"></script> 
 
<script src="https://code.jquery.com/jquery-migrate-1.2.1.min.js"></script> 
 
     
 
    </head> 
 
    <body> 
 
     <tbody> 
 
      <tr id="product_1338_19903_0_0" class="cart_item last_item first_item address_0 odd"> 
 

 
      <!-- <td class="ct-wishList-image"> 
 
       <img style="width:100px;" src="admin/itempics/item_no.jpg" alt="item_no"> 
 
      </td>--> 
 
      <td class="ct-wishList-description"> 
 
       <p class="boughItemId"> 
 
        item_no<!--?php echo $row[ 'itemno']; ?--> 
 
       </p> 
 
      </td> 
 
      <td class="ct-wishList-description"> 
 
       <p class="product-name"> 
 
       <a href=""> 
 
        model_name<!--?php echo $row[ 'model_name']?--> 
 
       </a> 
 
       </p> 
 
      </td> 
 
      <td class="ct-wishList-price"> 
 
       10000,00 kr 
 
       </td> 
 
      <td class="cart_quantity text-center"> 
 
       <input class="itemBoughtQty" type='text' name='qtyitem_id' size="2" id='qtyitem_id' value="1" /> 
 
       </br> 
 
       <input type='button' onclick="subchange('item_id')" name='subtract' value='-' /><!--? /*subchange<?php echo $items_id; ?>()*/ ?--> 
 
       <input type='button' onclick="addchange('item_id',10000)" name='add' value='+' /><!--? /*subchange<?php echo $items_id; ?>()*/ ?--> 
 
      <script> 
 
       $(function() { 
 
        var nTotalCount = 0; 
 
        var szUrlString = "index.php?con=6&itemid="; 
 

 
        $("span[itempricetag='1'").each(function(tag) { 
 
        nTotalCount = Number($(this).html()) + Number(nTotalCount); 
 

 
        }); 
 
        $(".boughItemId").each(function(tag) { 
 
        szUrlString += $(this).html() + ","; 
 
        }); 
 

 
        szUrlString += "&qty="; 
 
        $(".itemBoughtQty").each(function(tag) { 
 
        szUrlString += $(this).val() + ","; 
 
        }); 
 
        $("#total_price").html(nTotalCount); 
 
        $("#cart_price").html(nTotalCount); 
 
        $("#cart_total").html(nTotalCount); 
 
        $("#total_total").html(nTotalCount); 
 
        $("#ptcl").attr("href", szUrlString + "&total=" + nTotalCount); 
 
       }); 
 
       //document.getElementById("total_price").innerHTML= $total; 
 
       function addchange (item_id , price) { // <-here add item_id , price 
 
        var item_value = document.getElementById("qty"+item_id).value;// change var item_value = document.getElementById("qty"+item_id).value++; 
 
        document.getElementById("qty"+item_id).value = Number(item_value)+1;// add 
 

 
        document.getElementById("total_product_price_1338_19903_0"+item_id).innerHTML = (Number(item_value)+1) * Number(price) ; 
 
        // change "total_product_price_1338_19903_0"+item_id 
 
        // (Number(item_value)+1) * Number(price) 
 

 
        //total_price 
 
        var nTotalCount = 0; 
 
        var szUrlString = "index.php?con=6&itemid="; 
 
        $("span[itempricetag='1'").each(function(tag) { 
 
        nTotalCount = Number($(this).html()) + Number(nTotalCount); 
 
        }); 
 

 
        $(".boughItemId").each(function(tag) { 
 
        szUrlString += $(this).html() + ","; 
 
        }); 
 
        szUrlString += "&qty="; 
 
        $(".itemBoughtQty").each(function(tag) { 
 
        szUrlString += $(this).val() + ","; 
 
        }); 
 
        $("#total_price").html(nTotalCount); 
 
        $("#cart_price").html(nTotalCount); 
 
        $("#cart_total").html(nTotalCount); 
 
        $("#total_total").html(nTotalCount); 
 
        $("#ptcl").attr("href", szUrlString + "&total=" + nTotalCount); 
 
       } 
 

 
       function subchange(item_id) { 
 
        var item_count = document.getElementById("qty"+item_id).value; 
 
        var price = "10000"; 
 
        if (item_count > 1) { 
 
        document.getElementById("qty"+item_id).value = Number(item_count)-1; 
 
        document.getElementById("total_product_price_1338_19903_0"+item_id).innerHTML = (Number(item_count)-1) * Number(price) ; 
 
        var nTotalCount = 0; 
 
        $("span[itempricetag='1'").each(function(tag) { 
 
         nTotalCount = Number($(this).html()) + Number(nTotalCount); 
 
        }); 
 
        $("#total_price").html(nTotalCount); 
 
        $("#cart_price").html(nTotalCount); 
 
        $("#cart_total").html(nTotalCount); 
 
        $("#total_total").html(nTotalCount); 
 
        $("#ptcl").attr("href", "index.php?con=6&total=" + nTotalCount); 
 
        } 
 
       } 
 
       </script> 
 
       
 
      </td> 
 
      <td id="cart_total" data-title="Total"> 
 
       <span itempricetag="1" class="cart_total" id="total_product_price_1338_19903_0item_id"> 10000 </span> 
 
      </tr> 
 

 
</tbody> 
 
    </body> 
 
</html>

これは、サンプル価格は10000と$ items_idです。 = item_id

+0

waoooo fabvilous ..ありがとうございます;) –

関連する問題