Hi there,
I am trying to come up with an instant price quote calculator in javascript.
it would be a simple one with six fields:
Quantity of mounts
Outside Top = Free type box
Outside Side = Free type box
Window Top = Free type box
Window Edge = Free type box
Colour = Free type box
A button to calulate the total
The results to display total a price with a formula of “outside top multiplied by 0.10 plus outside side multiplied by 0.10”
The rest of the options are just information for me.
If at all possible I would like the results button to email me the value of the fields at the time of displaying the price on screen for the customer.
I will then try to add a buy it now button at a later date.
I did see something similar to what I want on a forum like this, I have pasted it below. I don’t know if it can be altered to what I need.
Thanks in advance for any help
Ric
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Calc</title>
- <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
- <script type="text/javascript">
- <!--
- $(document).ready(function() {
- $('#calculateTotal').click(function() {
- var shirtsPrice = 10.50, perColorPrice = 5.99;
- var inputNum_of_Shirts = $('#shirts').val();
- var inputNum_of_FColor = $('#colorsOnFront').val();
- var inputNum_of_BColor = $('#colorsOnBack').val();
- var totalCost = (inputNum_of_Shirts*parseFloat(shirtsPrice))
- +(parseFloat(perColorPrice)*inputNum_of_FColor)
- +(parseFloat(perColorPrice)* inputNum_of_BColor );
- var perShirtCost = (parseFloat(shirtsPrice))
- +(parseFloat(perColorPrice)*inputNum_of_FColor)
- +(parseFloat(perColorPrice)*inputNum_of_BColor);
- $('#total').html(formatCurrency(totalCost));
- $('#perShirt').html(formatCurrency(perShirtCost));
- $('#result').css('display', 'block');
- });
- });
- // This Function I have searched from Web
- function formatCurrency(strValue)
- {
- strValue = strValue.toString().replace(/\$|\,/g,'');
- dblValue = parseFloat(strValue);
- blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
- dblValue = Math.floor(dblValue*100+0.50000000001);
- intCents = dblValue%100;
- strCents = intCents.toString();
- dblValue = Math.floor(dblValue/100).toString();
- if(intCents<10)
- strCents = "0" + strCents;
- for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
- dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
- dblValue.substring(dblValue.length-(4*i+3));
- return (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents);
- }
- -->
- </script>
- </head>
- <body>
- <form id="calc" name="calc">
- <p>
- <input id="shirts" name="shirts" type="text">
- <label for="shirts">Number of Shirts</label>
- </p>
- <p>
- <input id="colorsOnFront" name="colorsOnFront" type="text">
- <label for="colorsOnFront">Number of Colors on Front</label>
- </p>
- <p>
- <input id="colorsOnBack" name="colorsOnBack" type="text">
- <label for="colorsOnBack">Number of Colors on Back</label>
- </p>
- <p><input name="calculateTotal" id="calculateTotal" type="button" value="Calculate Total" /></p>
- <div id="result" style="display:none;"><strong>Total:</strong> <span id="total"></span> <strong>Per Shirt:</strong> <span id="perShirt"></span></div>
- </div>
- </form>
- </body>
- </html>