T
Trickynick1001
Hi, a newbie here. I don't have a real firm grasp on the idea of
Javascript, as I'm used to programming in Qbasic and C. I'm not used
to OOP. Anyway, I really don't have any idea what the problem is with
this code, it just simply won't work properly. Some of the functions
aren't done, but the main one gives me a Not a Number message in the
text box where the calculations are supposed to come up. I tried to
use a parseInt on my stuff, but it still won't work. Any help with
this would be appreciated. By the way, this is for school, so I
shouldn't really get people to write my program for me. . . I just want
advice. (By the way, if my computer science teacher comes across this.
.. . I'm not trying to cheat, I just need help!) The code is here:
<html> <head>
<title>Greaseburger's Greasy Burgers</title>
<script Language ="Javascript">
/****** GLOBAL VARIABLES ******/
var grndtot;
var drinkprices = new Array('1.00', '1.50', '1.75', '0.75');
var foodprices = new Array('2.25', '3.00', '3.00', '0.75', '0.5');
var dessertprices = new Array('1.25', '0.50', '2.50', '2.50', '3.25');
function confirm () {
var f = document.form01;
var p;
var foodtot;
var drinktot;
var desrttot;
var currenttot;
var grndtot;
p = parseInt(f.food1.value);
currenttot = p * foodprices[0];
foodtot += currenttot;
p = parseInt(f.food2.value);
currenttot = p * foodprices[1];
foodtot += currenttot;
p = parseInt(f.food3.value);
currenttot = p * foodprices[2];
foodtot += currenttot;
p = parseInt(f.food4.value);
currenttot = p * foodprices[3];
foodtot += currenttot;
p = parseInt(f.food5.value);
currenttot = p * foodprices[4];
foodtot += currenttot;
p = parseInt(f.drink1.value);
currenttot = p * drinkprices[0];
drinktot += currenttot;
p = parseInt(f.drink2.value);
currenttot = p * drinkprices[1];
drinktot += currenttot;
p = parseInt(f.drink3.value);
currenttot = p * drinkprices[2];
drinktot += currenttot;
p = parseInt(f.drink4.value);
currenttot = p * drinkprices[3];
drinktot += currenttot;
p = parseInt(f.dsrt1.value);
currenttot = p * dessertprices[0];
desrttot += currenttot;
p = parseInt(f.dsrt2.value);
currenttot = p * dessertprices[1];
desrttot += currenttot;
p = parseInt(f.dsrt3.value);
currenttot = p * dessertprices[2];
desrttot += currenttot;
p = parseInt(f.dsrt4.value);
currenttot = p * dessertprices[3];
desrttot += currenttot;
p = parseInt(f.dsrt5.value);
currenttot = p * dessertprices[4];
desrttot += currenttot;
grndtot = foodtot + drinktot + desrttot;
f.orderamt.value = grndtot;
f.ordertax.value = addtax(grndtot);
}
function addtax (grndtot) {
return grndtot * 1.15;
}
function makechange () {
}
</script>
<body>
<form name = "form01">
<center>
<table align = "center" border = 4>
<tr>
<td><b>FOOD</b></td>
<td><b>DRINKS</b></td>
<td><b>DESSERT</b></td>
</tr>
<tr>
<td>
<table border = 1>
<td>AMT</td><td>Item</td><td>Price</td>
<tr>
<td><input type = "text" name = "food1" size = 2></td>
<td>HAMBRG</td>
<td>$2.25</td>
<tr>
<td><input type = "text" name = "food2" size = 2></td>
<td>CHEESE</td>
<td>$3.00</td>
<tr>
<td><input type = "text" name = "food3" size = 2></td>
<td>SALAD</td>
<td>$3.00</td>
<tr>
<td><input type = "text" name = "food4" size = 2></td>
<td>FRIES</td>
<td>$0.75</td>
<tr>
<td><input type = "text" name = "food5" size = 2></td>
<td>ADD BACN</td>
<td>$0.50</td>
</table>
<td>
<table border = 1>
<td>AMT</td><td>Item</td><td>Price</td>
<tr>
<td><input type = "text" name = "drink1" size = 2></td>
<td>FOUNTN</td>
<td>$1.00</td>
<tr>
<td><input type = "text" name = "drink2" size = 2></td>
<td>COFFEE</td>
<td>$1.50</td>
<tr>
<td><input type = "text" name = "drink3" size = 2></td>
<td>TEA</td>
<td>$1.75</td>
<tr>
<td><input type = "text" name = "drink4" size = 2></td>
<td>WATER</td>
<td>$0.75</td>
</table>
<td>
<table border = 1>
<td>AMT</td><td>Item</td><td>Price</td>
<tr>
<td><input type = "text" name = "dsrt1" size = 2></td>
<td>ICECRM</td>
<td>$1.25</td>
<tr>
<td><input type = "text" name = "dsrt2" size = 2></td>
<td>COOKIE</td>
<td>$0.50</td>
<tr>
<td><input type = "text" name = "dsrt3" size = 2></td>
<td>FROSTIE</td>
<td>$2.50</td>
<tr>
<td><input type = "text" name = "dsrt4" size = 2></td>
<td>CAKE</td>
<td>$2.50</td>
<tr>
<td><input type = "text" name = "dsrt5" size = 2></td>
<td>CRM BR</td>
<td>$3.25</td>
</table>
</table>
<input type = "button" name "doorder" value = "CONFIRM ORDER"
onClick = 'confirm ()'><br>
<table border = 0>
<td><b>Subtotal:</b></td>
<td><input type = "text" name = "orderamt" size = 10></td>
<tr>
<td><b>Grand Total:</b></td>
<td><input type = "text" name = "ordertax" size = 10></td>
<tr>
<td><b>CASH:</b></td>
<td><input type = "text" name = "cash" size = 10></td>
</tr>
<td colspan = 2>
<center>
<input type = "button" name = "change" value = "C/AT"
onClick = 'makechange()'></td>
<tr>
<td><b>CHANGE:</b></td>
<td><input type = "text" name = "chng" size = 10></td>
</center>
</tr>
</table>
</center>
</body> </html>
Javascript, as I'm used to programming in Qbasic and C. I'm not used
to OOP. Anyway, I really don't have any idea what the problem is with
this code, it just simply won't work properly. Some of the functions
aren't done, but the main one gives me a Not a Number message in the
text box where the calculations are supposed to come up. I tried to
use a parseInt on my stuff, but it still won't work. Any help with
this would be appreciated. By the way, this is for school, so I
shouldn't really get people to write my program for me. . . I just want
advice. (By the way, if my computer science teacher comes across this.
.. . I'm not trying to cheat, I just need help!) The code is here:
<html> <head>
<title>Greaseburger's Greasy Burgers</title>
<script Language ="Javascript">
/****** GLOBAL VARIABLES ******/
var grndtot;
var drinkprices = new Array('1.00', '1.50', '1.75', '0.75');
var foodprices = new Array('2.25', '3.00', '3.00', '0.75', '0.5');
var dessertprices = new Array('1.25', '0.50', '2.50', '2.50', '3.25');
function confirm () {
var f = document.form01;
var p;
var foodtot;
var drinktot;
var desrttot;
var currenttot;
var grndtot;
p = parseInt(f.food1.value);
currenttot = p * foodprices[0];
foodtot += currenttot;
p = parseInt(f.food2.value);
currenttot = p * foodprices[1];
foodtot += currenttot;
p = parseInt(f.food3.value);
currenttot = p * foodprices[2];
foodtot += currenttot;
p = parseInt(f.food4.value);
currenttot = p * foodprices[3];
foodtot += currenttot;
p = parseInt(f.food5.value);
currenttot = p * foodprices[4];
foodtot += currenttot;
p = parseInt(f.drink1.value);
currenttot = p * drinkprices[0];
drinktot += currenttot;
p = parseInt(f.drink2.value);
currenttot = p * drinkprices[1];
drinktot += currenttot;
p = parseInt(f.drink3.value);
currenttot = p * drinkprices[2];
drinktot += currenttot;
p = parseInt(f.drink4.value);
currenttot = p * drinkprices[3];
drinktot += currenttot;
p = parseInt(f.dsrt1.value);
currenttot = p * dessertprices[0];
desrttot += currenttot;
p = parseInt(f.dsrt2.value);
currenttot = p * dessertprices[1];
desrttot += currenttot;
p = parseInt(f.dsrt3.value);
currenttot = p * dessertprices[2];
desrttot += currenttot;
p = parseInt(f.dsrt4.value);
currenttot = p * dessertprices[3];
desrttot += currenttot;
p = parseInt(f.dsrt5.value);
currenttot = p * dessertprices[4];
desrttot += currenttot;
grndtot = foodtot + drinktot + desrttot;
f.orderamt.value = grndtot;
f.ordertax.value = addtax(grndtot);
}
function addtax (grndtot) {
return grndtot * 1.15;
}
function makechange () {
}
</script>
<body>
<form name = "form01">
<center>
<table align = "center" border = 4>
<tr>
<td><b>FOOD</b></td>
<td><b>DRINKS</b></td>
<td><b>DESSERT</b></td>
</tr>
<tr>
<td>
<table border = 1>
<td>AMT</td><td>Item</td><td>Price</td>
<tr>
<td><input type = "text" name = "food1" size = 2></td>
<td>HAMBRG</td>
<td>$2.25</td>
<tr>
<td><input type = "text" name = "food2" size = 2></td>
<td>CHEESE</td>
<td>$3.00</td>
<tr>
<td><input type = "text" name = "food3" size = 2></td>
<td>SALAD</td>
<td>$3.00</td>
<tr>
<td><input type = "text" name = "food4" size = 2></td>
<td>FRIES</td>
<td>$0.75</td>
<tr>
<td><input type = "text" name = "food5" size = 2></td>
<td>ADD BACN</td>
<td>$0.50</td>
</table>
<td>
<table border = 1>
<td>AMT</td><td>Item</td><td>Price</td>
<tr>
<td><input type = "text" name = "drink1" size = 2></td>
<td>FOUNTN</td>
<td>$1.00</td>
<tr>
<td><input type = "text" name = "drink2" size = 2></td>
<td>COFFEE</td>
<td>$1.50</td>
<tr>
<td><input type = "text" name = "drink3" size = 2></td>
<td>TEA</td>
<td>$1.75</td>
<tr>
<td><input type = "text" name = "drink4" size = 2></td>
<td>WATER</td>
<td>$0.75</td>
</table>
<td>
<table border = 1>
<td>AMT</td><td>Item</td><td>Price</td>
<tr>
<td><input type = "text" name = "dsrt1" size = 2></td>
<td>ICECRM</td>
<td>$1.25</td>
<tr>
<td><input type = "text" name = "dsrt2" size = 2></td>
<td>COOKIE</td>
<td>$0.50</td>
<tr>
<td><input type = "text" name = "dsrt3" size = 2></td>
<td>FROSTIE</td>
<td>$2.50</td>
<tr>
<td><input type = "text" name = "dsrt4" size = 2></td>
<td>CAKE</td>
<td>$2.50</td>
<tr>
<td><input type = "text" name = "dsrt5" size = 2></td>
<td>CRM BR</td>
<td>$3.25</td>
</table>
</table>
<input type = "button" name "doorder" value = "CONFIRM ORDER"
onClick = 'confirm ()'><br>
<table border = 0>
<td><b>Subtotal:</b></td>
<td><input type = "text" name = "orderamt" size = 10></td>
<tr>
<td><b>Grand Total:</b></td>
<td><input type = "text" name = "ordertax" size = 10></td>
<tr>
<td><b>CASH:</b></td>
<td><input type = "text" name = "cash" size = 10></td>
</tr>
<td colspan = 2>
<center>
<input type = "button" name = "change" value = "C/AT"
onClick = 'makechange()'></td>
<tr>
<td><b>CHANGE:</b></td>
<td><input type = "text" name = "chng" size = 10></td>
</center>
</tr>
</table>
</center>
</body> </html>