JSFiddle - React, Tailwind, and code Playground
HTML
<form id="calc" name="calc">
<p>
<H1>Quote Builder</H1>
</p>
<p>Please input the number of songs you wish to submit for mixing. </p>
<p>
<input id="mixes" name="mixes" type="text" />
<label for="mixes">Number of mixes</label>
</p>
<p>Optional Extras (ÂŁ25 each):</p>
<p>
<input type="checkbox" name="extras" value="25" class="chk-option" /> <label for "mixes">24bit Stems (ready for mastering)</label>
</p>
<p>
<input type="checkbox" name="extras" value="25" class="chk-option" /> <label for "mixes">A Capella Mix</label>
</p>
<p>
<input type="checkbox" name="extras" value="25" class="chk-option" /> <label for "mixes">Instrumental Mix</label>
</p>
<p>
<input name="calculateTotal" id="calculateTotal" type="button" value="Calculate Total" />
</p>
<div id="result" style="clear:both;">
<strong>Total:</strong>
<span id="total"></span>
<strong>Per mix:</strong>
<span id="permix"></span>
</div>
</form>
JavaScript
$(document).ready(function() {
$('#calculateTotal').click(function() {
//individual mix price before reduction
var mixPriceIndiv = 50;
//number of mixes selected by user
var nummixes = parseInt($('#mixes').val());
//get mix price based on number of mixes
var mixPrice = getmixPrice(nummixes);
//for each of the chk-option checkboxes, add values if checked
$('.chk-option').each(function() {
if( $(this).is(':checked') ) {
mixPrice+= parseInt($(this).val());
}
});
//grand total
$('#total').html('£' + mixPrice.toFixed(2));
//per mix
$('#permix').html('£' + mixPriceIndiv.toFixed(2));
});
function getmixPrice(el) {
numS = parseInt(el);
//calculate mix price
shPrice = 50*numS;
//get percentage value based on number of mixes e.g. if 2 mixes, take off 1%
percentVal = (el!==1) ? ((numS-1)/100)*shPrice : 1
//get mix price minus the percentage
mixPrice = (el!==1) ? (50*el) - percentVal : 50
//console.log(mixPrice);
return mixPrice;
}
});