remedy.
remedy.

Reputation: 2022

Dropdownlist not updating onchange when using Dependent Dropdowns

I have three dropdown lists which are dependent on each other. I want to be able to set the third DD to null whenever the first dropdown is chosen but so far my script is not doing anything. It's updating the second DD but not the third.

When all DD's are set and I update the 1st DD, it updates the 2nd but does not set the 3rd to null.

Here is my script:

echo CHtml::dropDownList('island_id',$island,$locationsList, 
          array('ajax'=>array('type'=>'POST',
                'url'=>CController::createUrl('supplierHead/getRegions'),
                'update'=>'#region_id',),
                'id'=>'island_id',
                'empty'=>'Choose Island',
                'onchange'=>'$("#province_id").html("<option value=''>Choose Province</option>")'
     )); 
echo " ";
echo CHtml::dropDownList('region_id',$region, $regionsList, 
          array('ajax'=>array('type'=>'POST',
                'url'=>CController::createUrl('supplierHead/getProvinces'),
                'update'=>'#province_id',),
                'id'=>'region_id',
                'empty'=>'Choose Region',
     ));
echo " ";
echo CHtml::dropDownList('province_id',$province,$provincesList, array('empty'=>'Choose Province'));

Upvotes: 1

Views: 500

Answers (1)

Sayed
Sayed

Reputation: 631

Try this:

echo CHtml::dropDownList('island_id',$island,$locationsList, 
          array('ajax'=>array('type'=>'POST',
                'url'=>CController::createUrl('supplierHead/getRegions'),
                'update'=>'#region_id',),
                'id'=>'island_id',
                'empty'=>'Choose Island',
                'onchange'=>'$("#province_id,#region_id").children().html("<option value=''>Choose Province/region</option>")'
     )); 

Upvotes: 1

Related Questions