my code:

protected function _prepareForm()

    $form = new Varien_Data_Form();
    $fieldset = $form->addFieldset("tuition_form", array("legend"=>Mage::helper("tuition")->__("Student information")));

    $fieldset->addField("secondary", "multiselect", array(              
        "class" => "required-entry",
        "required" => true,
        "name"=>  "subject[secondary]",
        'values'   => Example_Tuition_Block_Adminhtml_Student_Grid::getValueArray34(),
     $fieldset->addField("others", "text", array(                   
        "class" => "required-entry",
        "required" => true,
        "name"=>  "subject[others]",


        // The content of the "form_after" block is a Mage_Adminhtml_Block_Widget_Form_Element_Dependence block typ
            ->addFieldMap('junior', 'junior')
            ->addFieldMap('others', 'others')

       ->addFieldDependence('others', 'junior', 'chinese')
   return parent::_prepareForm();

my multiple dropdown

enter image description here

here if i m select chinese i want text field. if i m select chinese,malay,...etc than i m getting textbox but when i m also select physics or science that time i m not getting textbox how to solve this problem?

  • So, you are trying to have a multi select dropdown? and the selected values should be shown in the above text box? – Mr_Green Aug 11 '15 at 11:30
  • Nooo, i have multi select dropdown if i m select chinese i want to display textbox. not shown in textbox,its empty textbox it should be display in form if i select chinese otherwise it should be hide – ND17 Aug 11 '15 at 11:32
  • Write a click event on those list item elements. Whenever user clicks on a list item, the click event gets triggered, in that triggered function you can display a textbox based on the text inside that clicked list item. – Mr_Green Aug 11 '15 at 11:34
  • it is in admin side not in frontend – ND17 Aug 11 '15 at 11:36
  • 1
    please provide code for your form.php and edit.php files if you have to add functionality in admin section. – amit_game Aug 11 '15 at 11:48

Here using javascript i can show or hide textbox not using dependency:

$field = $fieldset->addField("junior", "multiselect", array(
    "class" => "required-entry",
    "required" => true,
    "name" => "subject[junior]",
    'onchange' => 'change(this.value)',
    'values' => Example_Tuition_Block_Adminhtml_Student_Grid::getValueArray35(),

        function change(selectItem){

            var e = document.getElementById('junior');
            var arr = new Array();
                for (var i = 0; i < e.options.length; i++) {
                        var val = e.options[i].value;
            var values = arr.indexOf('chinese');
            if (values != -1) { 
                document.getElementById('others').style.display = '';
            } else {
                document.getElementById('others').style.display = 'none';   

$other = $fieldset->addField("others", "text", array(
    "class" => "required-entry",
    "required" => true,
    "name" => "subject[others]",

                document.getElementById('others').style.display = 'none';               

Using this I can show and hide textbox on change of multiple dropdown.

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.