PDA

View Full Version : Cost Calculator Help!

Trnxrdm
04-04-2011, 05:45 AM
I want the calculator to take what was clicked display the item number and also the cost. (if possible i'd like to be able to display cost with no button) sorry if the code is messy i'm new to javascript.

<SCRIPT TYPE="TEXT/JAVASCRIPT">
// Definitions
var in2 = ""
var in3 = ""
//costs
var \$mat = ""
var cmat = Number(\$mat)
var \$sqft = ""
var csf = Number(\$sqft)
var chngcost = cmat*csf
var \$coga = 30
var \$cos = 40
var \$coshp = 15
var \$total = chngcost + \$coga + \$cos + \$coshp
// Add a letter to string
function itemnumber2(numb) {
in2 = numb
document.myform.i2.value = in2
document.itemnumber.i2.value = in2
if (in2 == "10") {
\$mat = 3
document.myform.cmat1.value = \$mat
}
if (in2 == "11") {
\$mat = 6
document.myform.cmat1.value = \$mat
}
if (in2 == "12") {
\$mat = 12
document.myform.cmat1.value = \$mat
}
}
function itemnumber3(numb) {
in3 = numb
document.myform.i3.value = in3
document.itemnumber.i3.value = in3
if (in3 == "1") {
\$sqft = 7.5
document.myform.sqrf1.value = \$sqft
}
if (in3 == "2") {
\$sqft = 5.5
document.myform.sqrf1.value = \$sqft
}
if (in3 == "3") {
\$sqft = 5
document.myform.sqrf1.value = \$sqft
}
}
//total cost function
function totalcost() {
ttc1 = \$total
document.myform.ttc.value = ttc1
}
</SCRIPT>

<input type="radio" id="10" name="Size" value="18x22" onclick="itemnumber2(10)"> 18" X 22"<br>
<input type="radio" id="11" name="Size" value="24x36" onclick="itemnumber2(11)"> 24" X 36"<br>
<input type="radio" id="12" name="Size" value="36x48" onclick="itemnumber2(12)"> 36" X 48"<br>

<input type="radio" id="1" name="Material" value="Photo Gloss" onclick="itemnumber3(1)"> Photo Gloss<br>
<input type="radio" id="2" name="Material" value="Bond Laminate" onclick="itemnumber3(2)"> Bond Laminate<br>
<input type="radio" id="3" name="Material" value="Photo Gloss" onclick="itemnumber3(3)"> Vinyl<br>

<form name="itemnumber" action="#">
<span class="style6">Item # <input type="text" size="3" name="i1" value="101" disabled>-
<input type="text" size="2" name="i2" disabled>-<input type="text" size="1" name="i3" disabled></span></p>
</form>

<input name="cost" type="button" onclick="totalcost()" value="Cost">
\$<input type="text" size="5" name="ttc" disabled>

bullant
04-04-2011, 11:56 AM
The very first problem that sticks out with your code is incorrect comparison operators (http://www.w3schools.com/JS/js_comparisons.asp)

Trnxrdm
04-04-2011, 04:05 PM
thnx that helped but i still cant get them to multiply and then add up with the other costs for a total...