0

I have 3 select boxes that are being populated from a database. I then use this javascript to make them cascade (dependent on selection in parent select box):

function cascadeSelect(parent, child){
var childOptions = child.find('option:not(.static)');
child.data('options',childOptions);

parent.change(function(){
    var parentValue = (this.value).replace(" ", "_");
    childOptions.remove();
    child
        .append(child.data('options').filter('.sub_' + parentValue))
        .change();
})

childOptions.not('.static, .sub_' + parent.val()).remove();
}

This works fine on native select boxes. The problem is that when I use jQuery Chosen, all of the options are returned in every select box regardless of what is selected in previous box (parent).

Link to build page here: http://site4.i-ocom.com/ Three select box ids are: #Make_395, #Model_395, #Trim_395 I have read the docs for chosen and have tried:

 $("#Make_395").chosen().change(function(){
 $("#Model_395").trigger('chosen:updated');
 });

 $("#Model_395").chosen().change(function(){
 $("#Trim_395").trigger('chosen:updated');
 });

as well as some other things that did not work. Any help is greatly appreciated as I am stumped.

1 Answers1

1

Actually you have very old version of chosen plugin (0.14 while latest version on github is 1.1) so things from the manual may not work for you. Update your js and try again.

osharper
  • 443
  • 4
  • 12
  • Wow *facepalm thanks! works fine now. I would vote up but I am new and have no rep :( But thanks again! –  Mar 07 '14 at 21:41
  • Well everything is almost working but now the update lags a step behind. If I select a model no trim is returned. If I then select a second model, the trim for the first model is returned. My understanding of the .change event is that the event should trigger right away... –  Mar 07 '14 at 22:54