Hi there,
I'm trying to create an instant price calculator in Javascript . Similar to https://mixam.co.uk/brochures but hopefully less complicated.
I have 4 fields;
'Paper Size'
'Pages'
'Numbering'
'Quantity'
I've managed to work out the code below following guides on other helpful websites.
Currently it shows the correct price once you select the the following fields, Paper Size, Pages, Numbering.
However the problem I have is with the Quantity, like all print jobs the price gets cheaper the more you buy.
Once the code works out the price for 1 Pad, the script will then work out the price for the different quantitys.
For example
1 Pad would be 'totalpadcost' * 1
2 Pads would be 'totalpadcost' * 2
10 Pads would be 'totalpadcost' * 1.75
<script type="text/javascript">
var prices = {
'dl' : '9.00' ,
'a6' : '10.00' ,
'a5' : '15.00' ,
'a4' : '25.00' ,
'a3': '35.00' ,
'2 Part' : '0.00' ,
'3 Part' : '20.00' ,
'4 Part' : '35.00' ,
'Yes' : '7.50' ,
'No': '00.00' ,
'1' : '00.00' , <-- Quantity Price
'2' : '2' ,
'3' : '1.9' ,
'4' : '1.85' ,
'5' : '1.8' ,
'10' : '1.75' ,
'15' : '1.70' ,
'20' : '1.65' ,
'25' : '1.60' ,
'50' : '1.55' ,
'75' : '1.50' ,
'100' : '1.45' <-- Quantity Price
}
function addem(oSelect)
{
var total = 0, oForm = oSelect.form;
var i = 0, sel, sels = oForm.getElementsByTagName('select');
while (sel = sels[i++])
if (sel.className == 'items')
total += parseFloat(prices[sel.options[sel.selectedIndex].value]|| 0, 10);
document.getElementById('output').value = format(total);
}
function format(sAmount)
{
sAmount = Math.round(sAmount * 100) / 100;
return '£' + ((sAmount != parseInt(sAmount)) ? sAmount : sAmount + '.00');
}
</script>
</head>
<body>
<form>
<tr>
<td class="label"><label for="pa_din-sizes">Paper Sizes</label></td>
<select class="items" name="items1" onchange="addem(this)">
<option>Paper Size</option>
<option value="dl">DL</option>
<option value="a6">A6</option>
<option value="a5">A5</option>
<option value="a4">A4</option>
<option value="a3">A3</option>
</select>
<td class="label"><label for="pa_din-sizes">Pages</label></td>
<select class="items" name="items2" onchange="addem(this)">
<option>Pages</option>
<option value="2 Part">2 Part</option>
<option value="3 Part">3 Part</option>
<option value="4 Part">4 Part</option>
</select>
<td class="label"><label for="pa_din-sizes">Numbering</label></td>
<select class="items" name="items3" onchange="addem(this)">
<option>Numbering</option>
<option value="Yes">Yes</option>
<option value="No">No</option>
</select>
<td class="label"><label for="pa_din-sizes">Quantity</label></td>
<select class="items" name="items4" onchange="addem(this)">
<option>Quantity</option>
<option value="1" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
<option value="4" >4</option>
<option value="5" >5</option>
<option value="10" >10</option>
<option value="15" >15</option>
<option value="20" >20</option>
<option value="25" >25</option>
<option value="50" >50</option>
<option value="75" >75</option>
<option value="100" >100</option>
</select>
<input type="text" name="output" id="output">
</form>
</body>
<!-- END --->
<script language="javascript">
<!--
function sendText(){
var solu = document.getElementById('d1')[document.getElementById('d1').selectedIndex].value;
document.getElementById('price').value = solu
}
// -->
</script>
Hopefully that makes sence, I am new to Java so don't do too hard on me.
Any questions please let me know.
Thanks in advance.
Adam