By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
462,316 Members | 577 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 462,316 IT Pros & Developers. It's quick & easy.

Function that allows me to create new dropdowns from previous dropdown

P: 4
Hello all,

I'm fairly new to javascript, and this is what I'm looking for:

I'm pulling information from a database to a dropdown menu and I need to create a function so that when an item is selected, a new dropdown appears with the same dropdown minus whatever item was selected, I would like for this process to continue infinitely until a drop down is no longer selected. Any examples/ ideas are greatly appreciated.

Oct 24 '08 #1
Share this Question
Share on Google+
5 Replies

P: 55
Based on what you said, it sounds like you need to look into "cloneNode" and "removeChild". This is a neat article about dynamically copying form fields on your site with javascript:)

QuirksMode domform
Oct 25 '08 #2

P: 4
Thanks, this is definitely what I was looking for and certainly puts me on the right track. I am having a difficult time getting the code for this example to execute as it does on the page, do you see anything at all wrong with the code he is using as an example? Or am I doing something wrong? I am also struggling to understand exactly where and how the function moreFields is called within the html.
Oct 27 '08 #3

P: 4
Ok, so I got the form to do what I hoped, which is create an infinite number of dropdowns with an input box next to each selection for entering a $ amount. Now, my final question is: Is there a way to sum the values entered into these boxes?

Help is again appreciated!

Oct 27 '08 #4

P: 55
when you submit you could call a function to do it....e.g.:

Expand|Select|Wrap|Line Numbers
  1. function submitMyForm(form){
  2.    var concat;
  3.    var i;
  4.    for(i in form.elements){
  5.       if(form.elements[i].value){
  6.         concat+=parseFloat(form.elements[i].value)
  7.       }
  8.    } 
  9.    return concat
  10. }
Oct 28 '08 #5

Expert Mod 5K+
P: 5,390
hi ... just a note ... i wouldn't use a variable name that is a reserved word for a native js-method that is implemented for strings/arrays ... even when it would work while its used in this local scope here in the shown function ... but its just a rule of thumb to avoid such reserved names for variables in your code ... it could be really hard to debug in case you don't handle that with great care and something ever goes wrong later on ... so just avoiding that just avoids this potential errors that will drive you crazy when they occur - i promise that ;) ... i made a review some weeks ago because of a strange behaviour of an app - i took us 3h to find out that it was the variable named with a JS-keyword that made this problem ...

as i said ... its just a hint to avoid a potential problem ;)

kind regards
Oct 29 '08 #6

Post your reply

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