|
How to do a price calculator
I am trying to create a price calculator that automatically calculates the price of custom made picture frame. I got an equation that finds the square area of the frame by multiplying the perimeter (2*length*width) by the thickness (which the user can choose from 1.5", 2" or 3"). Then it multiplies it by a decimal number (0.27 if the frame is 1.5" thick, 0.23 if its 2" thick, and 0.18 if its 3" thick). Then it adds a $5 custom made fee to the final answer. But when I save it to an html file and load it in Internet Explorer, it doesn't calculate. Do you guys have an idea how to make it work?
<SCRIPT LANGUAGE="JavaScript">
function calculate_total(){
var length = Number(document.
getElementById('calc').
length.value);
var width = Number(document.
getElementById('calc').
width.value);
var frame = Number(document.
getElementById('calc').
frame.options
[document.getElementById('calc...
frame.options.
selectedIndex].value);
var total = (2 * (length + width)) * frame;
switch (frame){
case 1.5:
total = total * 0.27;
break;
case 2:
total = total * 0.23;
break;
case 3:
total = total * 0.18;
break;
}
document.getElementById('calc'... = total + 5;
}
</script>
Sorry the cut off code so you might have to concatenate some lines above this if you have questions let me know.
And here is the form I used, again its very basic but it works.
<form name="calc" id="calc">
Length: <input type="text" name="length" onchange="calculate_total()" /><br />
Width: <input type="text" name="width" onchange="calculate_total()" /><br />
<select name="frame" onchange="calculate_total()">
<option value="0" selected>Select a Frame</option>
<option value="1.5">1.5" Narrow Barnwood</option>
<option value="2">2" Rustic Barnwood</option>
<option value="3">3" Thick Barnwood</option>
</select>
<br />
<br />
Total: <input id="total" name="total"/>
</form>
|