hi friends i use some inputs with same class and i done the sum and tax calculation with codes but my problem starts when i want to add a feature that if Check box checked it will calculate the tax if not checked it will not calculate it ! this is my code please help friends
<input name="pr-price[]" type="text" class="ad-money ad-price-item" placeholder="price">
<input name="pr-price[]" type="text" class="ad-money ad-price-item" placeholder="price">
<input name="pr-price[]" type="text" class="ad-money ad-price-item" placeholder="price">
<input name="pr-sum" type="text" class="uk-form-width-large ad-money ad-sum-a" value="0">
<input name="pr-discount" type="text" class="uk-form-width-large ad-money ad-discount" value="0">
<input id="ctax" type="checkbox"><label for="ctax">check to count tax</label>
<input name="pr-tax" type="text" class="uk-form-width-large ad-money ad-tax" value="0">
<input name="pr-finalsum" type="text" class="uk-form-width-large ad-money ad-finalsum" value="0">
<script type="text/javascript">
$(document).on("change", ".ad-money", function() {
var sum = 0;
$(".ad-price-item").each(function(){
sum += +$(this).val();
});
$(".ad-sum-a").val(sum);
var sumb = 0;
sumb = sum - $(".ad-discount").val();
var sumc = 0;
tax = .09;
sumc = sum * (1.00 + tax) - sum;
sumcround = Math.round(sumc);
$(".ad-tax").val(sumcround);
var sumfinal = 0;
sumfinal = sumb + sumcround;
$(".ad-finalsum").val(sumfinal);
});
</script>
Aucun commentaire:
Enregistrer un commentaire