views:

2263

answers:

2
+3  A: 

Hi,

The problem with the original plugin code is that it doesn't fire the change event after it manipulates the dropdown.

Also, I like to think of this problem in terms of 'dependency' and not 'cascading'. I have tried to create a simple plugin and a demo page which shows how the whole thing works.

Demo: http://jsbin.com/unope

Code: http://jsbin.com/unope/edit

Let me explain what I have done. I have created the plugin named 'dependent' which lets you associate dependency for a drop down.

e.g.

$('#dropDown2').dependent({ 
                            dependency : 'dropDown1',
                            values : getValues
                        });

Above code suggests that dropDown2 is dependent on dropDown1, so whenever dropDown1 value changes, it will call your getValues function (passing it dropDown1). You should return relevant values from your getValues function and it will populate them in dropDown2.

Keep in mind that this code is not generic, I have quickly wrote it to demonstrate the concept. You will have to tweak it further to achieve your desired result.

Let me know if you have any questions.

SolutionYogi
Thank you very much
omoto
A: 

SolutionYogi,

I'm trying to retrieve data dynamically through php/mysql within the getValues function using $.ajax. I'm returning multiple output.push strings but can not seem to get them to push into the output array.

Any ideas?

Thanks,

  • Dane
teamdane