Reputation: 1625
i've got the following radio buttons in a form
<input type="radio" name="shipping" value="Shipping($30)">Express Shipping($30)
<input type="radio" name="shipping" value="Shipping($15)">Regular Shipping($15)
<input type="radio" name="shipping" value="Shipping(Free)">Free Shipping
and the variables
$totalNoShip;
$totalWithShip;
The totalNoShip
variable holds the total before shipping.
I want the variable totalWithShip
to be updated when one of the radio buttons is clicked.
once this is done I want to print the variable in a span <span class="finalPrice"> final value here </span>
how do i go about doing this?
Upvotes: 0
Views: 94
Reputation: 1384
Change your HTML to
<input type="radio" name="shipping" value="30">Express Shipping($30)
<input type="radio" name="shipping" value="15">Regular Shipping($15)
<input type="radio" name="shipping" value="0">Free Shipping
<input type="hidden" name="total" value="0">
<span class="finalPrice"></span>
Then do something with JS like:
$(document).ready(function(){
$('input[name="shipping"]').click(function(){
var $mValue = $(this).val();
$('.finalPrice').text($mValue);
$('input[name="total"]').val($mValue);
});
});
Then after you POST, Validate your total to see if it is related to the selected Shipping type
Upvotes: 2