<script async> $(document).ready(function() { // fix dropdown width var dropdown = $('select[name="Mindestlaufzeit"]'); dropdown.parents('div.dropdown-list').css('width','auto'); // get purchase pricing var priceArr = dropdown.parents('table').find('tbody tr td:nth-child(2)').map(function(){ // match extracts the first price (in case there are multiple prices) var p = parseFloat($(this).text().match(/^([\d\.,]*\s€)/)[0].replace(/[€\.\s]/g,'').trim()); console.log("Base Price: " + p); return p; }).get(); dropdown.change( function() { let min_duration = $(this).val(); let index = dropdown.prop('selectedIndex'); let tds = $(this).parents('table').find('tbody tr td:nth-child(3)'); tds.each( function(tdIndex) { let purchasePrice = priceArr[tdIndex]; //let price = priceArr[tdIndex] / ((parseInt(min_duration, 10)/1.75) + (12 + index)); let price = purchasePrice / ((parseInt(min_duration, 10)/1.75) + ((16 + index) - Math.sqrt(min_duration))); if (price <= 7) { price = 7; }; let priceTag = Number(price) $(this).text(priceTag.toFixed(2).replace('.',',') + " €"); } ); } ); dropdown.prop('selectedIndex', 2); dropdown.change(); // calculate on load }); </script> |