473,382 Members | 1,373 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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 1227
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

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

Similar topics

15
by: binnyva | last post by:
Hello Everyone, I have just compleated a JavaScript tutorial and publishing the draft(or the beta version, as I like to call it) for review. This is not open to public yet. The Tutorial is...
39
by: Hareth | last post by:
C# 2005 express & vb 2005 express: 1. During runtime, I can edit my codes in C#..... How come this cannot be done in VB? it says ...."read-only" during runtime...... 2. Why does vb...
0
by: rayone | last post by:
Hi folks. I need advice. 2 options, which do you think is the better option to display/retrieve/report on the data. Keep in mind reporting (Crystal), SQL Performance, VB Code, usability,...
1
by: sneha123 | last post by:
There will be some 20 questions and for each question there will be 4 choices.what i want to do is to select multiple answers by clicking the checkbox. i m using asp.net,vb.net pls help me we...
7
by: Dave | last post by:
Apologies for the newbie question. I have created a vb.net program for my company that is designed to work with Word Templates (about forty of them that we commonly use) that are selected by the...
4
by: Matt Kruse | last post by:
While developing an internal IE6-only webapp, a discussion started about the 'best' way to apply classes to data tables across multiple pages. The two arguments were: 1. Apply a single class to...
2
by: newjazzharmony | last post by:
All, I'd appreciate it if someone could answer these questions for me. This scenario applies to an ASP dot net application that is deployed in a web farm. 1) Does the application live in a...
16
by: marc_r_bertrand | last post by:
To all asp/db pros: The quiz code below works. But there is a problem when too many questions are answered (radio buttons clicked). I am not an asp pro. So, is there a pro out there or an...
5
by: phpCodeHead | last post by:
I am needing to determine how to go about validating that a field in my form contains only a positive integer. I know that this is fairly simple if the form contains only one element to be...
8
by: Krypto | last post by:
Hi, I have used Python for a couple of projects last year and I found it extremely useful. I could write two middle size projects in 2-3 months (part time). Right now I am a bit rusty and trying...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.