How can I apply the if statement and calculate a set of radio buttons using JavaScript?
Ok what i would like to do is when the click on yes it will subtract $150 off the total.
<p>Baby Plan<br />
[radio BPSUBPT id:BPSUBPT class:radio-vertical "Baby Plan $500.00 3 Sessions" "Baby Plan $700.00 4 Sessions"] </p>
<p>Did you have a Newborn session With ADP? <br />
[radio BPSUPQ id:BPSUPQ class:radio-vertical "Yes" "No"]</p>
<p>Baby Plan Totals: <br />
Baby Plan Price: [text BPSUBPP 28/28 id:BPSUBPP]
Discount Amount: [text BPSUDA 10/10 id:BPSUDA]
Balance Amount: [text BPSUBA 8/8 id:BPSUBA]
Total Price: <span id="total"></span>
My java script
<script>
$(document).ready(function() {
var inputs = $('input[name="BPSUBPT"], input[name="BPSUPQ"]');
$(inputs).click(function() {
var total = 0;
$(inputs).filter(':checked').each(function() {
// Now including the - sign
var value = ($(this).val()).match(/$(-?[0-9]*)/)[1];
if (value) {
// I'm now ADDing the total
// total = total + parseInt(value);
total += parseInt(value);
}
});
$('#total').html('$' + total);
$('#BPSUBA').val('$' + total);
});
$('input[name="BPSUBPT"]').click(function() {
$(this).blur();
$('#BPSUBPP').val($(this).val());
})
$('input[name="BPSUPQ"]').click(function() {
$(this).blur();
$('#BPSUDA').val($(this).val());
});
}); </script>
Aucun commentaire:
Enregistrer un commentaire