jquery - Dynamic form Javascript dropdown/input -


i using plugin crowdfunding plateform working fine , helping me lot not quite confortable coding yet.

however i'd tweak javascript function. when customer chooses how wants contribute, customer can either decide amount or reward level wants

here how form made:

<form action="" method="post"> <div class="form-row inline left twothird">     <label for="level_select">contribution level         <span class="dropdown ">             <select name="level_select" class="dropdown__select">                 <option value="1" data-price="5.00">reward 1</option>                 <option value="1" data-price="15.00">reward 2</option>                 <option value="1" data-price="25.00">reward 3</option>         </span>     </label> </div> <div class="form-row inline third total">     <label for="total">total</label>     <input type="text" class="total" name="total" id="total" value=""> </div> <div class="form-row submit">     <input type="submit"> </div> 

from there want bind levels amount entered user. currently, partially working changing amount depending on selected level pretty easy. i'm stuck changing selected option depending on input.

in plugin found following lines seems i'm interested in:

    jquery(document).bind('price_change', function(event, price) {     jquery('input[name="total"]').val(price);     var levelindex = jquery('select[name="level_select"]').prop('selectedindex');     var levelprice = jquery('select[name="level_select"] option').eq(levelindex).data('price');     if (price < levelprice) {         jquery('input[name="total"]').val(levelprice);     } }); 

based on started tweak bit low knowledge of jquery here @ moment:

jquery(document).ready(function() { jquery(document).bind('price_change', function(event, price) {     var price = jquery('input.total').val();     var levelindex = jquery('select[name="level_select"]').prop('selectedindex');     var levelprice = jquery('select[name="level_select"] option').eq(levelindex).data('price');     var nextlevel = jquery('select[name="level_select"] option').eq(levelindex + 1);//got check if exist, else null     if (nextlevel){var nextlevelprice = jquery('select[name="level_select"] option').eq(levelindex + 1).data('price');}     var prevlevel = jquery('select[name="level_select"] option').eq(levelindex - 1);//got check if exist, else null     if (prevlevel){var prevlevelprice = jquery('select[name="level_select"] option').eq(levelindex - 1).data('price');}     while (prevlevel!=null && price < levelprice) {         jquery('input[name="total"]').val(prevlevel);     }     while (nextlevel != null && price < nextlevelprice){         jquery('input[name="total"]').val(nextlevel);     } }); 

am on right track or easier way proceed?

thank attention, advice appreciated


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -