469,273 Members | 1,786 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,273 developers. It's quick & easy.

multiple questions for javascript pros

6
Hello,

I'm Greg, a beginner in javascript, and I have a homework at university, to create a sort of a "pizza online-order website". I must give the option (through a FORM) for the buyer to specify how much, how large and what kind of pizza he wants to eat, and wether he wants it to be delivered or not. That part is done, sort of, I searched for a lot of things for my javascript on the internet, and found things, but now I'm stuck, so I need help. I need to count the cost, for example there are the pizzas, if you say you want two, and you enter 2 to one of the textboxes, the Count button should calculate the order. But I just don't know how to do it, I tried, but somehow, it doesn't seem to allow my script there, and if that part is not working, the other parts of the script are also not working! Also, I don't know that, if it's counted, how can I print the sum of the costs to the other side of the table, for example into a label.

The site is at:

http://irx.inf.elte.hu/~begoaai/pizzaboy/index2.html

The code is pretty messy, e.g. there are three buttons which do the same, but anyway...
May 6 '07 #1
2 1103
pbmods
5,821 Expert 4TB
if you say you want two, and you enter 2 to one of the textboxes, the Count button should calculate the order. But I just don't know how to do it,
Looking at your code, probably the easiest way to calculate the costs (without using custom attributes, which your instructor probably wouldn't approve of), would be to create an object to store the per-pizza cost and then write a function that totals up the cost:

Expand|Select|Wrap|Line Numbers
  1. var pizzaCosts = {
  2.     p1db:    6.75,
  3.     p2db:    7.80,
  4.     etc.
  5. };
  6.  
  7. function totalOrder() {
  8.     var theTotal = 0;
  9.  
  10.     for(var i = 0; i < 16; i++)
  11.         theTotal += (pizzaCosts['p' + i + 'db'] * parseInt(document.getElementById('p' + i + 'db').value));
  12.  
  13.     document.getElementById('theTotal').value = theTotal;
  14. }
  15.  
I tried, but somehow, it doesn't seem to allow my script there,
You'll have to explain that one in more detail.

Also, I don't know that, if it's counted, how can I print the sum of the costs to the other side of the table, for example into a label.
Welcome to DOM, bendes.

http://www.w3schools.com/htmldom/default.asp
May 6 '07 #2
bendes
6
Wow, thanks for the fast and accurate answer, I will try and learn from what you've written down. If I have other questions, I will ask them later, now I try and concentrate what I can do with the script.

Thanks again for the help,

Greg
May 6 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

15 posts views Thread by binnyva | last post: by
39 posts views Thread by Hareth | last post: by
4 posts views Thread by Matt Kruse | last post: by
2 posts views Thread by newjazzharmony | last post: by
8 posts views Thread by Krypto | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.