javascript - Why my numbers are not updating by themselves? -


so, using jquery-calx calculate price of items. have different price depending on base choise , quantity. if user chooses 100 peaces of full color base price different 100 pieces of 1 side monochromatic pattern. working in code, there thing; if choose 1 side monochromatic , them 100 pieces, price in total area ok, if change base full color, example, price doesn't update. in case, if click again in quantity price update. know if possible make update smoothly. maybe create button update, don't know. appreciate help! below follows code:

<form class="form-horizontal" id="meishi" data-calx-identifier="calx1452836013763">    <div class="form-group">     <label class="col-lg-1 topic text-left">base</label>     <div class="col-lg-2">       <label class="radio-inline">         <input type="radio" name="design" data-cell="a1" value="10800">one side monochromatic       </label>     </div>     <div class="col-lg-3">       <label class="radio-inline">         <input type="radio" name="design" data-cell="b1" value="14040">one side color       </label>     </div>     <div class="col-lg-2">       <label class="radio-inline">         <input type="radio" name="design" data-cell="c1" value="16200">full color       </label>     </div>     <div class="col-lg-2 col-lg-offset-2 text-right">       <label data-cell="f1" data-formula="sum(a1:c1)" data-format="$ 0,0"></label>     </div>   </div>    <div class="form-group">     <label class="col-lg-1 topic text-left">quantity</label>     <div class="col-lg-2">       <label class="radio-inline">         <input class="maisuua" type="radio" name="quantity" data-cell="a3" value="">100       </label>     </div>     <div class="col-lg-2">       <label class="radio-inline">         <input class="maisuub" type="radio" name="quantity" data-cell="b3" value="">200       </label>     </div>     <div class="col-lg-2">       <label class="radio-inline">         <input class="maisuuc" type="radio" name="quantity" data-cell="c3" value="">300       </label>     </div>     <div class="col-lg-2">       <label class="radio-inline">         <input class="maisuud" type="radio" name="quantity" data-cell="d3" value="">400       </label>     </div>     <div class="col-lg-1">       <label class="radio-inline">         <input class="maisuue" type="radio" name="quantity" data-cell="e3" value="">500       </label>     </div>     <div class="col-lg-2 text-right">       <label data-cell="f3" data-formula="sum(a3:e3)" data-format="$ 0,0"></label>     </div>   </div>    <div class="form-group">     <label class="col-lg-1 topic text-left">total</label>     <div class="col-lg-3 text-right col-lg-offset-8">       <label data-cell="f6" data-format="$ 0,0" data-formula="sum(f1:f5)">$ 0</label>     </div>   </div> </form> 

script:

$('#meishi').calx();  $('input:radio[name="design"]').change(   function() {    if ($(this).is(':checked') && $(this).val() == '10800') {     $('.maisuua').val('2160');     $('.maisuub').val('2484');     $('.maisuuc').val('3132');     $('.maisuud').val('2808');     $('.maisuue').val('3456');   } else if ($(this).is(':checked') && $(this).val() == '14040') {     $('.maisuua').val('2808');     $('.maisuub').val('3132');     $('.maisuuc').val('3780');     $('.maisuud').val('3456');     $('.maisuue').val('4104');   } else if ($(this).is(':checked') && $(this).val() == '16200') {     $('.maisuua').val('3240');     $('.maisuub').val('3564');     $('.maisuuc').val('4212');     $('.maisuud').val('3888');     $('.maisuue').val('4536');   } }); 

thank you!

i've never used jquery-calx isnt necessary this. if me, i'd this:

  • store array of values on design inputs
  • give of inputs class of update
  • when input changed, array selected design input , index of selected "maisuu" input tells value use stored array
  • get quantity value of selected "maisuu" elemet
  • do math , set total

like this:

*note may need tweak math, not 100% sure calculations intended. also, if insist, i'm sure merge technique use of jquery-calx

here's jsfiddle comments explaining code

$('.update').change(function() {    var $design = $('input[name="design"]:checked');    var $maisuu = $('input.maisuu:checked');    var curmaisuu =$('.maisuu').index($maisuu);    var maisuuarr =$.map($design.data('values').split(','), function(e, i) {      return number(e);    });    var base = $design.val() * 1000;       var upcharge = maisuuarr[curmaisuu] * 1000     var qty = $maisuu.val();     var cost = ((base + upcharge)* qty ) / 1000    if (base && qty) $('#total').text('$' + cost.tofixed(2))  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>  <form class="form-horizontal" id="meishi" data-calx-identifier="calx1452836013763">      <div class="form-group">      <label class="col-lg-1 topic text-left">base</label>      <div class="col-lg-2">        <label class="radio-inline">          <input class="update" type="radio" name="design" data-cell="a1" value="108.00" data-values="21.60,24.84,31.32,28.08,34.56">one side monochromatic        </label>      </div>      <div class="col-lg-3">        <label class="radio-inline">          <input class="update" type="radio" name="design" data-cell="b1" value="140.40" data-values="28.08,31.32,37.80,34.56,41.04">one side color        </label>      </div>      <div class="col-lg-2">        <label class="radio-inline">          <input class="update" type="radio" name="design" data-cell="c1" value="162.00" data-values="32.40,35.64,42.12,38.88,45.36">full color        </label>      </div>      <div class="col-lg-2 col-lg-offset-2 text-right">        <label data-cell="f1" data-formula="sum(a1:c1)" data-format="$ 0,0"></label>      </div>    </div>      <div class="form-group">      <label class="col-lg-1 topic text-left">quantity</label>      <div class="col-lg-2">        <label class="radio-inline">          <input class="maisuu update" type="radio" name="quantity" data-cell="a3" value="100">100        </label>      </div>      <div class="col-lg-2">        <label class="radio-inline">          <input class="maisuu update" type="radio" name="quantity" data-cell="b3" value="200">200        </label>      </div>      <div class="col-lg-2">        <label class="radio-inline">          <input class="maisuu update" type="radio" name="quantity" data-cell="c3" value="300">300        </label>      </div>      <div class="col-lg-2">        <label class="radio-inline">          <input class="maisuu update" type="radio" name="quantity" data-cell="d3" value="400">400        </label>      </div>      <div class="col-lg-1">        <label class="radio-inline">          <input class="maisuu update" type="radio" name="quantity" data-cell="e3" value="500">500        </label>      </div>      <div class="col-lg-2 text-right">        <label data-cell="f3" data-formula="sum(a3:e3)" data-format="$ 0,0"></label>      </div>    </div>      <div class="form-group">      <label class="col-lg-1 topic text-left">total</label>      <div class="col-lg-3 text-right col-lg-offset-8">        <label id="total">$ 0</label>      </div>    </div>  </form>


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -