I made a calcul for checkboxes and it works well.
HTML code :
$(document).ready(function() {
function recalculate() {
//prix de base du séjour
var sum = 940;
//nb de participants au séjour
var nb_pax = parseInt(1+1);
$(".chk_box:checkbox:checked").each(function() {
sum += parseInt($(this).attr("price"))*nb_pax;
});
$(".budget").html(sum+' €');
}
$(".chk_box:checkbox").change(function() {
recalculate();
});
});
<script src="http://ift.tt/2a1Bldc"></script>
<div class="extra_libelle">
<label><input class="chk_box" type="checkbox" name="extras[]" price="142" value="1"> Transfers Ida/Volta (aeroporto-hotel-aeroporto)</label>
</div>
<br/>
<div class="extra_prix">142 €</div>
<div class="extra_libelle">
<label><input class="chk_box" type="checkbox" name="extras[]" price="45" value="1"> Rafting</label>
</div>
<br/>
<div class="extra_prix">45 €</div>
<div class="extra_libelle">
<label><input type="radio" class="chk_box2" name="transports" value="0" price="0" checked="checked"> Eu já tenho a minha solução de transporte</label>
</div>
<br/>
<div class="extra_prix">0 €</div>
<div class="extra_libelle">
<label><input class="chk_box2" type="radio" name="transports" price="396" value="6"> Voos Ida/Volta a partir de LISBOA (com transfers incluidos) </label>
</div>
<br/>
<div class="extra_prix">396 € </div>
<div class="extra_libelle">
<label><input class="chk_box2" type="radio" name="transports" price="596" value="6"> Voos Ida/Volta a partir de PORTO (com transfers incluidos) </label>
</div>
<br/>
<div class="extra_prix">596 € </div>
<P>
<br/><br/><span>SUBTOTAL Extras : </span><span class="budget_extras">0 €</span>
<br/><br/><span>SUBTOTAL Transports : </span><span class="budget_extras">0 €</span>
<br/><br/><span>TOTAL : </span><span class="budget">940 €</span>
</p>
this is my code here : http://ift.tt/2lXg8Bm
But I want to make a bit more complex and the problem is :
- I don't know how to add the same calcul for radio button
- I don't know how to separate the subtotal to keep the subtotal of extras and subtotal of transport (to submit by POST method in input hidden later).
Any help appreciate.
Aucun commentaire:
Enregistrer un commentaire