459,934 Members | 1,476 Online
Need help? Post your question and get tips & solutions from a community of 459,934 IT Pros & Developers. It's quick & easy.

# Total drop down boxes

 P: n/a Hi all, I have a page with 5 or 6 drop down boxes, all ranging from 1 to 100. After each is selected, I need a box that will show a total of all the results. So basically, dropdown 1 + dropdown 2 + dropdown 3 = box. A thousand bonus points if someone can tell me how to make sure the box doesn't = >100. (These are percentages) Thank-you very much in advance. If I can return the favor (in any way), don't hesitate to ask. Thanks!!! Aimee Nov 19 '06 #1
7 Replies

 P: n/a st*****@gmail.com said the following on 11/19/2006 4:13 PM: Hi all, I have a page with 5 or 6 drop down boxes, all ranging from 1 to 100. After each is selected, I need a box that will show a total of all the results. So basically, dropdown 1 + dropdown 2 + dropdown 3 = box. Did you try reading the group FAQ? How do I get the value of a form control?: How do I convert a string to a number? sel1 = +document.forms['formName'].elements['select1Name'].value; sel2 = +document.forms['formName'].elements['select2Name'].value; sel3 = +document.forms['formName'].elements['select3Name'].value; sel4 = +document.forms['formName'].elements['select4Name'].value; var totalValue = sel1 + sel2 + sel3 + sel4; document.forms['formName'].elements['theTotal'].value = totalValue; A thousand bonus points if someone can tell me how to make sure the box doesn't = >100. (These are percentages) if(totalValue >100){alert('I want your school grade also!!!')} Thank-you very much in advance. If I can return the favor (in any way), don't hesitate to ask. Do I get your homework grade? -- Randy Chance Favors The Prepared Mind comp.lang.javascript FAQ - http://jibbering.com/faq Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/ Nov 19 '06 #2

 P: n/a st*****@gmail.com wrote: Hello, So basically, dropdown 1 + dropdown 2 + dropdown 3 = box. Randy has already provided appropriate reference on how to achieve your task. I shall add some kind of example, so that you can experiment a bit more - have fun, Elegie. --- --- Nov 20 '06 #3

 P: n/a Elegie wrote: st*****@gmail.com wrote: Hello, So basically, dropdown 1 + dropdown 2 + dropdown 3 = box. Randy has already provided appropriate reference on how to achieve your task. I shall add some kind of example, so that you can experiment a bit more - have fun, Elegie. --- I'm reading through now. Thank-you for the tips, I'll reply with how it goes! Nov 20 '06 #4

 P: n/a Randy, Thank-you for the links! I actually found a suitable clip of code by googling off of that information. Being an absolute beginner, I wasn't able to take your code clips and put it into a usable .html file. This doesn't mean I can't! I just haven't figured it out yet. Homework- so you're a comedian as well? ; Thing is, I'm a networking person- I'm only editing this site because I'm the closest they have to computer person at the moment :/ Elegie, Your script did exactly what I asked (thank-you!) but not what I wanted (my fault!). In this case, I was able to change the amount of dropdowns by editing the value "5" under the "buildselects" area, but again, you are way out of my league. Because the drop downs are all created identically, I wasn't able to assign a "name" value or add a text label to each. If I can restate what the end solution should look like: Dropdown 1 has [select name="1"] and values = [0% to 100%] Dropdown 2 has [select name="2"] and values = [0% to 100%] Dropdown 3 (etc) TextBox 1: [Total of All Dropdowns] Heck, if I could get this far, I could go to sleep tonight (It's approaching 4a east coast US). Idealy though, "Textbox 1" would remain "red" or something until the value = 100. Or even a line of text next to it that said "this doesn't equal 100% yet". An alert box won't work because I don't want alerts coming up while end-users are still selecting dropdowns. If you guys can help, thank-you- if you can't, no worries. You've gotten me in the right direction. Cheers! PS Code so far: Autosum DropDown
Value A
Value B
Total  =  % Nov 20 '06 #5