Hi,
I have to make a pizza ordering form and when I click the order button it should display the total price in a field. Here is what I have so far. I have no idea how to make it display in the field when I click on the order button. Please help.
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“
<html xmlns=”
<!– Author: Hanley Chan
Date: March 17, 2004
Purpose: A program for ordering a pizza.
–>
<head>
<title>Ordering a Pizza</title>
<script language=”JavaScript” type=”text/javascript”>
function TotalQuantity()
{
var Quantity;
Quantity = document.form1.Quantity.value;
return Quantity;
}
function PriceSize()
{
var PriceSize;
if (document.form1.Size[0].checked)
{
PriceSize = 10;
}
if (document.form1.Size[1].checked)
{
PriceSize = 15;
}
if (document.form1.Size[2].checked)
{
PriceSize = 20;
}
return PriceSize;
}
function PriceTopping()
{
var NumTopping = 0;
var PriceTopping;
if (document.form1.Topping[0].checked)
{
NumTopping++;
}
if (document.form1.Topping[1].checked)
{
NumTopping++;
}
if (document.form1.Topping[2].checked)
{
NumTopping++;
}
PriceTopping = NumTopping * 0.3;
return PriceTopping;
}
function PriceTotal()
{
var Quantity;
var SizePrice;
var ToppingPrice;
var TotalPrice;
Quantity = TotalQuantity();
SizePrice = PriceSize();
ToppingPrice = PriceTopping();
TotalPrice = “$” + Quantity * (SizePrice + ToppingPrice) + “0”;
return TotalPrice;
}
</script>
</head>
<body>
<noscript>
<h2>You really need JavaScript to view this page!</h2>
</noscript>
<h1>Please fill in your pizza order in the form below:</h1>
<form name = “form1” action = “”>
Quantity: <br />
<input type = “text” name = “Quantity” size = “2” value = “1”> <br /><br />
Size: <br />
<input type = “radio” name = “Size” value = “Small” /> Small($10 each)
<input type = “radio” name = “Size” value = “Medium”/> Medium($15 each)
<input type = “radio” name = “Size” value = “Large” checked = “checked” /> Large($20 each) <br /><br />
Toppings($0.30 for each topping): <br />
<input type = “checkbox” name = “Topping” /> Pepperoni
<input type = “checkbox” name = “Topping” /> Pineapples
<input type = “checkbox” name = “Topping” /> Ham <br /><br />
<input type = “button” name = “Order” value = “Order” /><br />
Summary:
<input type = “text” name = “Summary” value = “$0.00” onblur = “value = PriceTotal()”/>
</form>
<address>
<a href=”
src=”
alt=”Valid XHTML 1.0!” /></a>
</address>
</body>
</html>