snotrocket
04-23-2008, 02:15 AM
Ok, so I am making a form which asks for pizza information, then reports it in a textarea at the bottom. I have two problems with this so far.
The input for the type of toppings the person gets is in two sections using checkboxes. One for meat, one for vegetables. I have a problem storing the type of topping they want. An example is here.
for(i=0;i<myForm.meat.length;i++){
if(myForm.meat[i].checked==true){
c= myForm.meat[i].value;
meatCount++;
}
}
When I use that code, it only reports the last checkbox entered.
The second problem is with the textarea. That is where I want to output the information that has been calculated. So far I use
write("baseprice: " + pizzaType + ":" + pizzaPrice + "<br/>"
+ "meat toppings: " + c + " " + meatCount + " x " + meatToppingPrice + " = " + meatPrice + "<br/>"
+ "veg. toppings: " + d + " " + veggieCount + " x " + veggieToppingPrice + " = " + veggiePrice + "<br/>"
+ "total of toppings: " + totalToppingPrice + "<br/>"
+ "total price: " + totalPrice);
This above code outputs the information, but on a separate page.
I tried using
<textarea id="orderSummary" name="summary" rows="5" cols = "50">
<script>
write("baseprice: " + pizzaType + ":" + pizzaPrice + "<br/>"
+ "meat toppings: " + c + " " + meatCount + " x " + meatToppingPrice + " = " + meatPrice + "<br/>"
+ "veg. toppings: " + d + " " + veggieCount + " x " + veggieToppingPrice + " = " + veggiePrice + "<br/>"
+ "total of toppings: " + totalToppingPrice + "<br/>"
+ "total price: " + totalPrice);
</script>
</textarea>
but that just output exactly what is inside the <textarea> lines.
My entire code is
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Assignment 8</title>
</head>
<body>
<script>
function next(){
with(document){
meatCount=0;
veggieCount=0;
veggieToppingPrice=1.5;
pizzaPrice=0;
meatToppingPrice=0;
if(forms[0].elements[0].checked==true){
b=forms[0].elements[0].value;
pizzaPrice=10;
pizzaType="medium";
}
else if(forms[0].elements[1].checked==true){
b=forms[0].elements[1].value;
pizzaPrice=13;
pizzaType="large";
}
for(i=0;i<myForm.meat.length;i++){
if(myForm.meat[i].checked==true){
c= myForm.meat[i].value;
meatCount++;
}
}
for(i=0;i<myForm.veggie.length; i++){
if(myForm.veggie[i].checked==true){
d=myForm.veggie[i].value;
veggieCount++;
}
}
if(forms[0].elements[0].checked==true){
meatToppingPrice=1.5;
}
else if(forms[0].elements[1].checked==true){
meatToppingPrice=3;
}
meatPrice=meatToppingPrice*meatCount;
veggiePrice=veggieToppingPrice*veggieCount;
totalToppingPrice=meatPrice+veggiePrice;
totalPrice=0;
write("baseprice: " + pizzaType + ":" + pizzaPrice + "<br/>"
+ "meat toppings: " + c + " " + meatCount + " x " + meatToppingPrice + " = " + meatPrice + "<br/>"
+ "veg. toppings: " + d + " " + veggieCount + " x " + veggieToppingPrice + " = " + veggiePrice + "<br/>"
+ "total of toppings: " + totalToppingPrice + "<br/>"
+ "total price: " + totalPrice);
}
}
</script>
<form id="myForm" name="myForm">
<p>
Choose pizza size:<br />
<input type="radio" value="m" name="size"/> medium($10)<br />
<input type="radio" value="l" name="size"/> large($13)
</p>
<p>meats: $1.50/topping for medium; $3/topping for large<br />
veggies: $1.50/topping for medium and large</p>
<hr/>
<table border="0">
<tr>
<th>pepperoni</th>
<th>sausage</th>
<th>bacon</th>
<th>hamburger</th>
<th>ham</th>
</tr>
<tr>
<th><input type="checkbox" value="pepperoni" name="meat"/></th>
<th><input type="checkbox" value="sausage" name="meat"/></th>
<th><input type="checkbox" value="bacon" name="meat"/></th>
<th><input type="checkbox" value="hamburger" name="meat"/></th>
<th><input type="checkbox" value="ham" name="meat"/></th>
</tr>
<tr>
<th>mushrooms</th>
<th>onions</th>
<th>peppers</th>
<th>tomato</th>
<th>olives</th>
</tr>
<tr>
<th><input type="checkbox" value="mushrooms" id="veggie" name="m"/></th>
<th><input type="checkbox" value="onions" id="veggie" name="o"/></th>
<th><input type="checkbox" value="peppers" id="veggie" name="pep"/></th>
<th><input type="checkbox" value="tomato" id="veggie" name="t"/></th>
<th><input type="checkbox" value="olives" id="veggie" name="ol"/></th>
</tr>
</table>
<hr/>
<input type="button" value="Calculate Order" onclick="next()"/>
<input type="reset" value="Reset Form"/>
<p>order summary:</p>
<textarea id="orderSummary" name="summary" rows="5" cols = "50"></textarea>
</form>
</body>
</html>
Thank you so much for your help.
The input for the type of toppings the person gets is in two sections using checkboxes. One for meat, one for vegetables. I have a problem storing the type of topping they want. An example is here.
for(i=0;i<myForm.meat.length;i++){
if(myForm.meat[i].checked==true){
c= myForm.meat[i].value;
meatCount++;
}
}
When I use that code, it only reports the last checkbox entered.
The second problem is with the textarea. That is where I want to output the information that has been calculated. So far I use
write("baseprice: " + pizzaType + ":" + pizzaPrice + "<br/>"
+ "meat toppings: " + c + " " + meatCount + " x " + meatToppingPrice + " = " + meatPrice + "<br/>"
+ "veg. toppings: " + d + " " + veggieCount + " x " + veggieToppingPrice + " = " + veggiePrice + "<br/>"
+ "total of toppings: " + totalToppingPrice + "<br/>"
+ "total price: " + totalPrice);
This above code outputs the information, but on a separate page.
I tried using
<textarea id="orderSummary" name="summary" rows="5" cols = "50">
<script>
write("baseprice: " + pizzaType + ":" + pizzaPrice + "<br/>"
+ "meat toppings: " + c + " " + meatCount + " x " + meatToppingPrice + " = " + meatPrice + "<br/>"
+ "veg. toppings: " + d + " " + veggieCount + " x " + veggieToppingPrice + " = " + veggiePrice + "<br/>"
+ "total of toppings: " + totalToppingPrice + "<br/>"
+ "total price: " + totalPrice);
</script>
</textarea>
but that just output exactly what is inside the <textarea> lines.
My entire code is
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Assignment 8</title>
</head>
<body>
<script>
function next(){
with(document){
meatCount=0;
veggieCount=0;
veggieToppingPrice=1.5;
pizzaPrice=0;
meatToppingPrice=0;
if(forms[0].elements[0].checked==true){
b=forms[0].elements[0].value;
pizzaPrice=10;
pizzaType="medium";
}
else if(forms[0].elements[1].checked==true){
b=forms[0].elements[1].value;
pizzaPrice=13;
pizzaType="large";
}
for(i=0;i<myForm.meat.length;i++){
if(myForm.meat[i].checked==true){
c= myForm.meat[i].value;
meatCount++;
}
}
for(i=0;i<myForm.veggie.length; i++){
if(myForm.veggie[i].checked==true){
d=myForm.veggie[i].value;
veggieCount++;
}
}
if(forms[0].elements[0].checked==true){
meatToppingPrice=1.5;
}
else if(forms[0].elements[1].checked==true){
meatToppingPrice=3;
}
meatPrice=meatToppingPrice*meatCount;
veggiePrice=veggieToppingPrice*veggieCount;
totalToppingPrice=meatPrice+veggiePrice;
totalPrice=0;
write("baseprice: " + pizzaType + ":" + pizzaPrice + "<br/>"
+ "meat toppings: " + c + " " + meatCount + " x " + meatToppingPrice + " = " + meatPrice + "<br/>"
+ "veg. toppings: " + d + " " + veggieCount + " x " + veggieToppingPrice + " = " + veggiePrice + "<br/>"
+ "total of toppings: " + totalToppingPrice + "<br/>"
+ "total price: " + totalPrice);
}
}
</script>
<form id="myForm" name="myForm">
<p>
Choose pizza size:<br />
<input type="radio" value="m" name="size"/> medium($10)<br />
<input type="radio" value="l" name="size"/> large($13)
</p>
<p>meats: $1.50/topping for medium; $3/topping for large<br />
veggies: $1.50/topping for medium and large</p>
<hr/>
<table border="0">
<tr>
<th>pepperoni</th>
<th>sausage</th>
<th>bacon</th>
<th>hamburger</th>
<th>ham</th>
</tr>
<tr>
<th><input type="checkbox" value="pepperoni" name="meat"/></th>
<th><input type="checkbox" value="sausage" name="meat"/></th>
<th><input type="checkbox" value="bacon" name="meat"/></th>
<th><input type="checkbox" value="hamburger" name="meat"/></th>
<th><input type="checkbox" value="ham" name="meat"/></th>
</tr>
<tr>
<th>mushrooms</th>
<th>onions</th>
<th>peppers</th>
<th>tomato</th>
<th>olives</th>
</tr>
<tr>
<th><input type="checkbox" value="mushrooms" id="veggie" name="m"/></th>
<th><input type="checkbox" value="onions" id="veggie" name="o"/></th>
<th><input type="checkbox" value="peppers" id="veggie" name="pep"/></th>
<th><input type="checkbox" value="tomato" id="veggie" name="t"/></th>
<th><input type="checkbox" value="olives" id="veggie" name="ol"/></th>
</tr>
</table>
<hr/>
<input type="button" value="Calculate Order" onclick="next()"/>
<input type="reset" value="Reset Form"/>
<p>order summary:</p>
<textarea id="orderSummary" name="summary" rows="5" cols = "50"></textarea>
</form>
</body>
</html>
Thank you so much for your help.