配送方法を選択して合計値を計算したいのですが、その値は注文の小計と合計されます。
しかし、配送方法の1つを選択してから別の配送方法を選択すると、新しいものと以前のものが選択された合計値になります。例えば。最初の合計: 200 で、[DHL 標準配送: $10.50] をクリック -> 合計 = 210.50。その後、「DHL Express delivery : $42.50」をクリック → 合計 = 252.50 ですが、242.50 のはずです
どうすればこれを解決できますか?
これが私のjQueryコードです
$("input:radio[name=shipping]").click(function(){
var total = 0;
$("input:radio[name=shipping]:checked").each(function() {
total += parseFloat($(this).val());
});
var current = parseFloat($('#total').val());
$("#shipping").html(total);
total += current;
$("input:text[name=total1]").val(total);
});
HTML コード
<tr valign="top">
<td>Select Shipping method</td>
<td>
<input id="shipping_method" type="radio" name="shipping" value="10.50"> DHL standard delivery : $10.50<br>
<input id="shipping_method" type="radio" name="shipping" value="42.50"> DHL express delivery : $42.50<br>
<input id="shipping_method" type="radio" name="shipping" value="0.00"> pick up : $0.00<br><br>
</td>
</tr>
<tr>
<td>Order Subtotal<td><label id="subtotal" value="">$200.00</label>
</tr>
<tr><td> </tr>
<tr>
<td>Shipping<td>$<span id="shipping">0.00</span>
</tr>
<tr><td> </tr>
<tr>
<td>Total<td> $<input type="text" id="total" name="total1" value="252.50" style="border:0px;">
</tr>