Internet Advertising - Wordpress Themes - Find jobs - Advertising - Submit articles

PDA

View Full Version : Filling up combo by selecting values of multiple combo in Javascript


computerzworld
Dec 16th 2008, 9:38 am
Hello All,
I want to fill up the combo by selecting values and text of multiple combo in Javascript.


I am having one multiple selection box which contains the values coming from database. And I want to fill up the second combo(single selection combo) from that because what is the exact requirement is that user can select multiple options & from that one will be default option. So, that what I require exactly is to select multiple combo & fill out its values in second one. And if user unselects some values the values in the second combo will also be removed.

How can I do this? Please help me. Thanks in advance.

rene7705
Dec 21st 2008, 10:55 pm
with a bit of javascript you can do that.

you make a function called updateComboBox() which will update the combobox with the selected values.
that function gets called from the onchange= for the multi-select box.

you have a second function called comboBoxItemSelected(), which -for now- only updates a global var with the selected value in the combobox. it gets called in the onchange= of the combobox.

updateComboBox will empty out the combobox, fill in the new selected values, and select the one that is equal to the global var mentioned in the previous paragraph..

As for the exact syntax to use, i'd have to look it up, but you can do that yourself too;
http://www.w3schools.com/TAGS/tag_Select.asp