View Single Post
Old 07-26-2006, 07:05 AM   #1 (permalink)
base1001
Junior Member
 
Join Date: Jul 2006
Posts: 1
Default forms, adding items, getting total. javascript

i am having problems w/ creating a form. the form needs to ad, "s, m, or l"(pizza size) in one box, then the quantity in another. m(medium) buy one get second for lower price. buy three large and get 10% off bill. i am pretty sure i should be using % somewhere because of the remainder...the functions i have are either wrong or don't need it. i know i am missing something. 1st quarter w/ javascript.

here it is. not of it works atm. any direction, help please.


<html>
<head><title>Maria's Pizza Parlor</title></head>
<body>

<!-- Display pizza stuff -->
<h1 align = "center">Pizza Stand</h1>
<table border = "2" width = "30%" align = "center">

<caption>pizza menu</caption>
<tr>
<th>size</th><th>price</th>
</tr>
<tr>
<td>small</td><td>$5.99 per pizza</td>

</tr>
<tr>
<td>medium</td><td>Buy one for $7.99; get the second for $4.99</td>
</tr>
<tr>
<td>large</td><td>$9.99 per pizza. Buy 3 or more and get 10% off your bill!</td>
</tr>

</table><br>
<hr><hr>

<!-- create a form for input/output, but organize it with a table -->
<form name = "pizza">
<table border = "0" width = "75%" align = "center">
<tr>
<td align = "right">S for Small<br>M for Medium<br>L for Large
<input type = "text"
name = "itemID"
size = "2">

<p>


Enter <b""</b> number of pizzas
<input type = "text"
name = "totalPizza"
size = "2">
</td>
<td align = "center">

<input type = "button"
name = "Bcalculate"
value = "Find cost"
onClick = "pizzaCost()">

</td>

<td width = "250" valign = "top">
<div id = "out"></div>
</td>
</tr>
</table>
</form>

<script language = "javascript">

//////////////////////////////////////////////////
// CALCULATION FUNCTION DEFINITION
/////////////////////////////////////////////////

/* calTotal() -- function to determine the pizza total
*
*/
function calTotal() {

var cost;
var size; // used for display
var special; // used for display
var goodData = true; // used to keep track if input is valid or not
var display = ""; // string to gather my display text
var mp;
var sp;
var lp;
var bill;
var totals = new Array();
var total="Total";

// INPUT though the itemID is a digit, we won't be doing any math with
// it, so leave it as a string
var type = document.pizza.itemID.value;
var howMany = document.pizza.pizzas.value;


// regardless of whether the user entered lower or upper case, I'll change
// that value to upper case so that we only have to test upper-case letters
type= itemSiz.toUpperCase();

// Let's make sure the user entered valid data
if (type != "s" && type != "m" && type !="l") {
alert("Invalid item number. Please try again");
goodData = false;
}


// only continue if we have good data
if (goodData) {

/* PROCESS: Pizza cost, super order menu viola
*/

if (type == "s"){
var small = 5.99;
}

else if (mp>1){
var medTotal=7.99*1
medtotal+=(4.99*(mp-1));
}

else if(lp>3){
bill=bill-(.10*bill)
}
}


//////////////////////////////////////////////////////
// EVENT HANDLER
//////////////////////////////////////////////////////

// OUTPUT finally, the results
display += "<font color = 'orange'><b>The cost of pizza is <u>" +
calTotal + "</u> for a <u>" +
Length +" day</u> is $"
+ cost.toFixed(2) + "</b></font>";
document.getElementById("out").innerHTML = display;
}
}
</script>

</body>

</html>
base1001 is offline   Reply With Quote
Sponsored Links