I have a select field like this in my costum magento admin form

        'id'    => 'lazadaCategory',
        'label'  => Mage::helper('test_sellercenter')->__('Category '),
        'name'   => 'status',
        'values' => Mage::helper('test_sellercenter/dropdown')->getLazadaCategories(),
        'class' => 'required-entry',

and when the select value change i need to add another fields below this select field (not like toogle show/hide just add), for example like this field

        'label' => Mage::helper('test_sellercenter')->__('Listing Name'),
        'name'  => 'listing_name',
        'required'  => true,
        'class' => 'required-entry',


is there a way to do this in magento? for example like this add field example

2 Answers 2


For that you can use field dependencies feature of Magento, like here is the example

$status = $fieldSet->addField('status', 'select', array(
    'label'     => Mage::helper('module')->__('Status'),
    'name'      => 'status',
    'values'    => array(
        'Approved' => 'Approved',
        'Denied'   => 'Denied'

$denyReason = $fieldSet->addField('denial_reason', 'textarea', array(
    'label'     => Mage::helper('module')->__('Denial Reason'),
    'name'      => 'denial_reason'

And add your dependencies

$this->setChild('form_after', $this->getLayout()->createBlock('adminhtml/widget_form_element_dependence')
    ->addFieldMap($status->getHtmlId(), $status->getName())
    ->addFieldMap($denyReason->getHtmlId(), $denyReason->getName())                     

$denyReason field only display If status is set to Denied. According to this you can define your field dependencies.

  • that's just like show/hide , what i want is like this link Dec 22, 2016 at 10:15
  • It was my bad ,, sorry :)
    – Keyur Shah
    Dec 22, 2016 at 10:16
  • No problem :), i hope you can help me with this question :D Dec 22, 2016 at 10:20

use setAfterElementHtml function. Suppose, you want to show/hide the following field:

$fieldset->addField('field_to_hide', text, array(
    'label'  => $this->__('Test'),

Here is the dropdown/select field. It’s a yes/no field. Suppose, upon selecting ‘Show’, you will need to show the above mentioned field. And, upon selecting ‘Hide’, you will need to hide the above field.

Note the onChange parameter here. It’s calling showHideField() JS function.

$selectField = $fieldset->addField('select_field', 'select', array(
    'label' => 'Show/Hide Selection',
    'name' => 'select_field',           
    'values' => array(
            'value' => 1,
            'label' => 'Show',
            'value' => 0,
            'label' => 'Hide',
    'onChange'  => 'showHideField()',

The setAfterElementHtml is called which contains Javascript code to show/hide field

    function showHideField() {                                              
  • i dont want to show/hide field, i need to add more field when onchange function triggered Dec 23, 2016 at 1:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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