Page 1 of 1

Triple Dynamic Drop down list

Posted: Wed Apr 04, 2012 9:31 pm
by mcgrathken.kmg

I have a Dynamic list working for 2 lists just like your Dynamic list tutorial, however i cannot get it to work for 3 select lists.
Can you kindly show how to achieve this using java Script and possibly expand on the tutorial.Perhaps something as shown below.
Much appreciated Image


Triple Dynamic Drop down list

Posted: Thu Apr 05, 2012 2:27 am
by maxkatz

What exactly is not working? Can you post the code that you tried?


Triple Dynamic Drop down list

Posted: Thu Apr 05, 2012 11:28 am
by mcgrathken.kmg

I am trying to extend your dynamic list example to work for 3 drop down lists.
The name of lists are
1.typeList
2.dynamicList
3.colorList
here is the code i am trying to extent.

---------------------------------------------------------------------------------------------------------

var selectedValue = this.value;

var data = { 'fruits': ['orange', 'apple', 'banana'],
'vegetables': ['onion', 'carrot', 'tomato']
'color': ['green', 'yellow','orange','red', 'brown']
};

var dropDown3 = $('[name=colorList]');
dropDown3.html('');
var newData = data[selectedValue];

for(i = 0; i < newData.length; i++) {
dropDown3.append('​' + newData + '');
}
dropDown.selectmenu('refresh');

---------------------------------------------------------------------------------------------------------

so basically if fruits and banana was chosen from list 1 & 2 then the colorList should be filtered to show just "yellow".
I have it working for 2 but I can get it working for 3.
There is other ways using Switch case statements but i would like to use the JavaScript from your tutorial as i have used it on other screens and would like to keep my code consistent.
Thanks again Max


Triple Dynamic Drop down list

Posted: Thu Apr 05, 2012 12:55 pm
by maxkatz

You are missing a comma after "'tomato']". There are might be other problems, but this is the first thing that I noticed.


Triple Dynamic Drop down list

Posted: Thu Apr 05, 2012 1:56 pm
by mcgrathken.kmg

I have put the comma in but it still didn't make a difference.
i require list 3 to show only what depends on what's select in list1 and list2.
Take example
'vegetables': ['onion', 'carrot', 'tomato']

there is one argument which says if vegetables is chosen then only display
'onion', 'carrot', 'tomato'
so my question is how do I give it 2 arguments which should only display in list 3 depending on selection in list1 and list2.

thanks Max


Triple Dynamic Drop down list

Posted: Thu Apr 05, 2012 2:11 pm
by maxkatz

You will need to add if-statements to check what fruit or vegetable combination was selected. Use the Console window in Chrome Developer Tools to debug your app. You can always put console.log(value) to print values.


Triple Dynamic Drop down list

Posted: Thu Apr 05, 2012 3:39 pm
by mcgrathken.kmg

Ok Max thanks.
I'm not to well up on using java Script can you please get me started where to begin using the example above.
Thanks Max


Triple Dynamic Drop down list

Posted: Thu Apr 05, 2012 5:06 pm
by maxkatz

If you Google, you will find large number of resources on how to use if-statement.