Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more

Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Web Design Forum > HTML / CSS
User Name
Password

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
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
Old 08-03-2006, 09:34 PM   #2 (permalink)
shane.carr
Junior Member
 
shane.carr's Avatar
 
Join Date: Jun 2006
Posts: 28
Default Re: forms, adding items, getting total. javascript

All new:

[html]

<!-- should go in the head tag -->
<script language="javascript">
function calcCost(){
var size = document.pizza.size.value;
var num = Number(document.pizza.num.value);
var smallcost = 5.99;
var medcost = 7.99;
var discountmed = 4.99;
var largecost = 9.99;
var discountlarge = Number(9) / Number(10); //90% of total cost
var cost = 0;
if(size == "s"){
cost = Number(smallcost) * Number(num);
}else if(size == "m"){
if(num < 2){
cost = Number(medcost) * Number(num);
}else{
//this will calculate as every even pizza at $4.99
var num2 = Math.floor(Number(num) / Number(2));
var num3 = Number(num) - Number(num2);
cost = Number(num2) * Number(discountmed);
cost = Number(cost) + (Number(num3) * Number(medcost));
}
}else if(size == "l"){
if(num < 3){
cost = Number(largecost) * Number(num);
}else{
cost = Number(largecost) * Number(num) * Number(discountlarge);
}
}else{
alert("The script was coded wrong.");
}
cost = Number(Math.round(Number(cost)*Number(100))) / Number(100);
alert("Cost: $"+cost);
}
</script>

<form name="pizza">
<select name="size">
<option value="s">Small</option>
<option value="m">Medium</option>
<option value="l">Large</option>
</select>
<p />
Number:&nbsp;&nbsp;<input type="text" name="num" />
<p />
<input type="button" onclick="javascript:calcCost();" value="Find Cost" />
</form>

[/html]
shane.carr is offline   Reply With Quote
Old 08-06-2006, 03:37 AM   #3 (permalink)
fares_refaat
Junior Member
 
Join Date: Aug 2006
Posts: 11
Default Re: forms, adding items, getting total. javascript

thank You Too much
fares_refaat is offline   Reply With Quote
Old 08-06-2006, 04:42 AM   #4 (permalink)
shane.carr
Junior Member
 
shane.carr's Avatar
 
Join Date: Jun 2006
Posts: 28
Default Re: forms, adding items, getting total. javascript

You're welcome!

P.S. base1001 started this thread; shouldn't he be the one thanking me?
shane.carr is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 1.00
Points Per Thread: 11.00
Points Per Reply: 5.00



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare
Dedicated Servers

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 11:58 AM.



LinkBacks Enabled by vBSEO 3.0.0 RC8
Webmaster Forums