javascript - jQuery on element unhidden, populate a div with text -


i have div displays information based on options chosen. there's few divs on page set hidden, when user selects options dropdown aren't holding text (like "please select..." or variant) price div populates price. ids , classes of options can change , there's no way determine them before hand (dynamically populated).

i've got div on page i'm looking populate when first price div becomes visible, extract amount it, perform calculation on , display it.

i thinking along lines of this:

jquery( "form.variations_form cart" ).children("div.single_variation").change(    function(){          /* update div */    } ); 

i've put down on jsfiddle can see please note comments. here's link jsfiddle: http://jsfiddle.net/scott_mcgready/h3g6a/1/

any idea on how monitor initial box, pull through price , display on other one?

working demo

try

i have edited html

html

<fieldset class="variations">     <div> <span class="select_label">colour</span>          <select id="colour-33" name="tax_colour-33">             <option value="">choose option …</option>             <option value="100">white/high gloss black</option>         </select>     </div>     <div>   <span class="select_label">installation</span>          <select id="installation-61" name="tax_installation-61">             <option value="">choose option …</option>             <option value="200">delivery only</option>             <option value="300">installation required</option>         </select>     </div> </fieldset> <!-- initial state of single_variation follows. changes options chosen , works well. <div class="single_variation" style="display: none;"></div> --> <!-- version of single_variation displays if options chosen --> <div class="single_variation" style="display: block;"><span>£</span><span class="price">579.00</span>      <p class="stock ">in stock</p> </div> <div class="boxthis" style="width: 100%; border: 1px solid black;"> <span id="disctext">     <p>you need choose options first can calculate price.</p>     </span>  </div> 

code

$(document).ready(function () {     var price = parsefloat($(".price").text())     var val1;     var val2;     $("#colour-33").change(function () {         if (parsefloat($("#colour-33 option:selected").val())) {             val1 = parsefloat($("#colour-33 option:selected").val());             price = price + val1;             $(".price").text(price);         } else {             price = price - val1;             $(".price").text(price);         }     });      $("#installation-61").change(function () {         if (parsefloat($("#installation-61 option:selected").val())) {             val2 = parsefloat($("#installation-61 option:selected").val());             price = price + val2;             $(".price").text(price);         } else {             price = price - val2;             $(".price").text(price);         }     }); }); 

hope helps,thank you


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -