vendredi 24 février 2017

Double sum data-price (basic price + one radio + all checkbox) Javascript

i have this script and it work fine but when i try to select one radio + check checkbox i have only basic price + checkbox value... But i want BASIC PRICE + ONE RADIO + ALL CHECKBOX IF CHECK,

i CAN'T use

if ($(".choice").find('input[type=checkbox]').is(':checked')) {

because input is position: absolute; left: 9999999999999px

I see only class choice so i can click only class choice

Can you help me? :)

if (document.getElementById("getPrice")) {
  var basePrice = parseFloat(document.getElementById("getPrice").value);
  $(".choice").click(function() {
    var newPrice = basePrice;
    newPrice += parseFloat($(this).attr('data-price'));
    newPrice = newPrice.toFixed(2);
    $("#item-price").html(newPrice);
  });
}
.choice {
  height: 50px;
  width: 50px;
  background: blue
}
<script src="http://ift.tt/1oMJErh"></script>
<input type="input" id="getPrice" value="899">

<div class="choice active" data-toggle="wizard-radio" rel="tooltip" data-price="99" title="" data-original-title="+ 99 PLN">
<input type="radio" class="calculate" name="option1" value="House" checked="checked">
</div>

<div class="choice active" data-toggle="wizard-radio" rel="tooltip" data-price="25" title="" data-original-title="+ 99 PLN">
<input type="radio" class="calculate" name="option1" value="House" checked="checked">
</div>

<div class="choice active" data-toggle="wizard-checkbox" rel="tooltip" data-price="122" title="" data-original-title="+ 99 PLN">
<input type="checkbox" class="calculate" name="option1" value="House" checked="checked">
</div>
<a id="item-price">899</a>



Aucun commentaire:

Enregistrer un commentaire