I have two Multi select Drop downs admin. i tried to make it dependent but not success.

Below is code :-

Multiselect 1:-

 $fieldset->addField('mainfiled_id', 'multiselect', array(
            'label' => Mage::helper('Custom')->__('custom main field'),
            'class' => 'required-entry',
            'required' => true,
            'name' => 'location_id',
            'values' => Mage::getSingleton('custom/userlocation')->getOptionArray(),

Multiselect 2:-

$fieldset->addField('dependent_ids', 'multiselect', array(
        'label' => Mage::helper('custom')->__('Dependent'),
        'class' => 'required-entry',
        'required' => true,
        'name' => 'pos_ids',
        'values' => Mage::getSingleton('custom/dependent')->getOptionArray(),

On based selection of Multiselect 1 need to update values of Multiselect 2.


You can manage to work this by use the concept of following code. I have added a code snippet which is for dropdowns. You need to change those according to your requirement.

$field = $fieldset->addField('dropdown', 'select', array(
    'label'     => Mage::helper('module1')->__('Dropdown'),
    'values'   => Vendor_Module1_Block_Adminhtml_Custom_Grid::getValueArray1(),
    'name' => 'dropdown',                   
    "class" => "required-entry",
    'onchange' => 'change(this.value)',
    "required" => true,

function change(selectItem){
    var reloadurl =  '". $this->getUrl('*/*/actionurl')."';

    new Ajax.Request(reloadurl, {
        method: 'get',
        parameters: {selectItem: selectItem},
        onSuccess: function(selectElement) {
        var results = JSON.parse(selectElement.responseText);

        if(typeof results.error != 'undefined') {
            document.getElementById('dropdown1').innerHTML = results.error;

        document.getElementById('dropdown1').innerHTML = results.image;

$fieldset->addField('dropdown1', 'select', array(
    'label'     => Mage::helper('module1')->__('Dropdown1'),
    'values'   => Vendor_Module1_Block_Adminhtml_Custom_Grid::getValueArray2(),
    'name' => 'dropdown1',

Here you need to create one controller action from where you need to return proper options html. Rest will be done by javascript. This is just a basic idea to use dependency fields in magento admin forms.

Note: Code was not tested.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.