I’m brand new to Javascript and I’m trying to create a four-box form in which the user enters information into the first two boxes, and the program fills the second two boxes in.
Basically, I need a form to calculate the square footage and cost of a vinyl banner.
In the first text box the user would enter the banner’s height.
In the second box the user would enter the banner’s width.
The third box would multiply the height by the width and display the total square footage of the banner.
So far, I have this part down. The following is what I need help with: the fourth box.
The fourth box needs to display the cost of the banner. I have a complicated pricing structure. For example:
If the total square feet for the banner is under 12 square feet, the cost is $60.00. If the square feet for the banner is between 13 and 25 square feet. The cost is $4.80/square foot and ect…
I believe this would be done using some variation of an IF statement but I can’t get it to work.
Using this example, what would I add to the form to get this work? The following is the form I have so far which just consists of the calculation of the square feet which is all I’ve been able to get working.
[CODE]<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Untitled Document</title>
</head>
<SCRIPT language = JavaScript>
function calculate() {
A = eval(document.frmOne.txtFirstNumber.value)
B = eval(document.frmOne.txtSecondNumber.value)
C = (A * B)
eval(document.frmOne.txtThirdNumber.value = C)
}
</SCRIPT>
<body><FORM NAME = frmOne>
Height: <INPUT TYPE = Text NAME = txtFirstNumber SIZE = 5 value =””>
Width: <INPUT TYPE = Text NAME = txtSecondNumber SIZE = 5 value =””>
Square Footage: <INPUT TYPE = Text NAME = txtThirdNumber SIZE = 5 value = “”>
<P>
<Input Type = Button NAME = b1 VALUE = “Add Numbers” onClick = calculate()>
</FORM>
</body>
</html>
Thanks for any help,
Nick.