473,403 Members | 2,359 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,403 software developers and data experts.

calcualtion using values in combobox

Hi,
I'll be grateful if anyone can help me with this query. I'm trying to create an online quote form. I have five combo boxes (combo1, combo2, combo3....) which are autoupdating on the basis of selection in the previous combo box. For each selection in the combo box there is some value attached to the selection. What I need is that as soon as the last combo box is selected, the HTML/script code should perform a calculation (basically multiply all the values) and display the result in a text box which has the readonly=true property. Code below is what I tried but nothing shows up in the text box names calc:

Expand|Select|Wrap|Line Numbers
  1.      function update()
  2. {
  3.  
  4.  var*combo1*=*document.getElementById("combo1"); 
  5.  var*combo2*=*document.getElementById("combo2");
  6.  var*combo3*=*document.getElementById("combo3");
  7.  var*combo4*=*document.getElementById("combo4");
  8.  var*combodelivery*=*document.getElementById("combo1delivery");
  9.  var*type*=*combo1.options[combo2.selectedIndex].value
  10.  var*standard*=*combo1.options[combo3.selectedIndex].value
  11.  var*level*=*combo1.options[combo1.selectedIndex].value
  12.  var*delivery*=*combo1.options[combodelivery.selectedIndex].value
  13.  var*length*=*combo1.options[combo4.selectedIndex].value
  14.  
  15. var total;
  16. total = level * length * standard * type;
  17.     calc.value="£ "+Math.round(total);
  18.  
  19.  
  20. }
Nov 12 '08 #1
7 3020
Hi,
I'll be grateful if anyone can help me with this query. I'm trying to create an online quote form. I have five combo boxes (combo1, combo2, combo3....) which are autoupdating on the basis of selection in the previous combo box. For each selection in the combo box there is some value attached to the selection. What I need is that as soon as the last combo box is selected, the HTML/script code should perform a calculation (basically multiply all the values) and display the result in a text box which has the readonly=true property. Code below is what I tried but nothing shows up in the text box names calc:

Expand|Select|Wrap|Line Numbers
  1. function update()
  2. {
  3.  
  4. var*combo1*=*document.getElementById("combo1"); 
  5. var*combo2*=*document.getElementById("combo2");
  6. var*combo3*=*document.getElementById("combo3");
  7. var*combo4*=*document.getElementById("combo4");
  8. var*combodelivery*=*document.getElementById("combo1delivery");
  9. var*type*=*combo1.options[combo2.selectedIndex].value
  10. var*standard*=*combo1.options[combo3.selectedIndex].value
  11. var*level*=*combo1.options[combo1.selectedIndex].value
  12. var*delivery*=*combo1.options[combodelivery.selectedIndex].value
  13. var*length*=*combo1.options[combo4.selectedIndex].value
  14.  
  15. var total;
  16. total = level * length * standard * type;
  17. calc.value="£ "+Math.round(total);
  18.  
  19.  
  20. }
Nov 12 '08 #2
acoder
16,027 Expert Mod 8TB
Not sure what all those *s are doing in your code in place of what should be spaces. Replace them with spaces first of all. If you look in your error console, you may see an error relating to the line which sets calc. You need to first get calc using document.getElementById() as you did with the combo boxes. Finally, the values are strings. To convert them to integers, use parseInt.
Nov 12 '08 #3
There are no stars in the actual code. I'm not sure why it is showing here. As for the value: suppose the code is for one value in combo box (name combodelivery) is:
<select name="combodelivery" id="combo_del" onChange="change(this);" style="width:312;height:312">
<option value="delivery">Delivery requirement </option>
<option value="1">Standard: 15 days </option>
<option value="1.25">Express: 10 days</option>
<option value="1.5">Speedy: 7 days</option>
<option value="2">Next day</option>
<option value="2.5">Same day</option>

Wont I set delivery=1 using this code:
var*delivery*=*combo1.options[combodelivery.selectedIndex].value
if the person has selcted the 'Standard:15 day' delivery option?
Nov 12 '08 #4
Just to solve the confusion. My code in frontpage is not showing any stars. But when I copy the code on this website, spaces are replaced by asterisks. I'm not sure why it is happening. The code works upto autopopulating combo boxes but nothing happens after the last combo box is autopopulated and selected.
Nov 12 '08 #5
acoder
16,027 Expert Mod 8TB
3 things:
  1. The variables on line 16 should be wrapped in parseFloat()s because the values are floats
  2. calc.value on line 17 should be document.getElementById("calc").value
  3. Why are you mixing the combo box and the selected index, e.g. you're getting the value of combo1, but using the selected index of combo delivery - is that what you meant to do?
Nov 12 '08 #6
Hi,
No this is not what I want. I'll tell you exactly what the code does. I select the first combo box which has options A, B, C, D. All four of these have a value of their own so A means 100, B means 50 and so on. Once the user selects an option the second combo box gets populated (depending on the choice made in the first combo box) with options say E,F,G,H. Again these options have some value. This cycle is repeated to get two more combo boxes with some value attached to their options as well. What I'm trying to do is that as soon as I select the fourth combo box, the readonly text box below the fourth combo box should display value x where x is simply the multiplication of the values attached to the options selected in the four combo boxes. Forget about autopopulating; what shall we do to capture the four selections, read the values attached to these options, calculate x and display it immediately after selection of the fourth combo box?
I am not sure what I am doing wrong. I know nothing about Javascript or in fact any script. I did web development in asp and HTML but some 5-6 years ago and have forgotten most of it. I understand coding a bit but I cant get this to work. Please help. Thanks in anticipation.
Nov 12 '08 #7
acoder
16,027 Expert Mod 8TB
So, the first two points still apply and so does the third. In your update() function, look at lines 9-13. They should be as follows:
Expand|Select|Wrap|Line Numbers
  1. var type = combo2.options[combo2.selectedIndex].value;
  2. var standard = combo3.options[combo3.selectedIndex].value;
  3. var level = combo1.options[combo1.selectedIndex].value;
  4. var delivery = combodelivery.options[combodelivery.selectedIndex].value;
  5. var length = combo4.options[combo4.selectedIndex].value;
Notice how I've changed the names. You can also just use the value property of the select element directly:
Expand|Select|Wrap|Line Numbers
  1. var type = combo2.value;
Nov 12 '08 #8

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

Similar topics

0
by: Gamze | last post by:
Hi, How can i get values from datagrid to combobox and should select the same name as in datagrid row on the combobox control In my vb.net windows application ,i have combobox which is...
3
by: google | last post by:
This is something I've done plenty of times in '97, but I can't seem to get it to work correctly in Access 2003. Say, for example, I have a form with an unbound combobox, the data source is a...
7
by: charliewest | last post by:
Using .Net CF, i have created a 2 dimension ArrayList, and "binded" this list to a ComboBox control using the "DataSource" property. I have set the DisplaySource and ValueMember properties as well....
10
by: Rick Palmer | last post by:
I have an app I'm working on that will allow a user to run one of 5 reports. The report names are in a combobox on my form. I have a sub defined for each report that has the exact same name as is...
5
by: James P. | last post by:
Hello, For my new Windows application, all I want is to create an initial form to demo to the user to show them how it looks like with some data on it. So I figure the fastest way is to create...
7
oll3i
by: oll3i | last post by:
i want to change the values in two columns one colum is a combobox and the secons column is editable too i want to get the value of that second column and the value of combobox and sent that...
1
by: sathyan8294 | last post by:
i am using dotnet 2003.i am doing my project in vb.net windows application.i have two form in my project.first form is datagrid .In second form label,textboxes and combobox are avilable to save the...
1
by: The.Daryl.Lu | last post by:
Hi, two parts to my problem if someone can help address either one or both: 1. I want to SELECT everything in the table if it matches the criteria when the query button is pressed (this is just...
2
by: lee.walczak | last post by:
Hi, I am using Tkinter & the Kevin Walzer's TableList Wrapper for python implemented GUI: http://tkinter.unpythonic.net/wiki/TableListWrapper The TableList has been extremely useful in...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.