简体   繁体   中英

Show elements dynamically in a zend form

i am using zend form and i have a condition such that:

when i select a value of a dropdown, i have to show a text field dynamically below the dropdown field.

And when i select another value of a dropdown, i have to show another field dynamically below the dropdown field.

I want to use ajax with onchange event of the dropdown field... how can i go ahead ?

This is my sample code of element creation in zend form:

$country = $this->createElement('select',’countries’);
            $country ->setLabel('Countries:')
                ->addMultiOptions(array(
                        'US' => 'United States',
                        'UK' => 'United Kingdom' 
                            ))
                ->setAttrib('id', 'country');
$country = $this->createElement('select',’countries’);
            $country ->setLabel('Countries:')
                ->addMultiOptions(array(
                        'US' => 'United States',
                        'UK' => 'United Kingdom' 
                            ))
                ->setAttrib('id', 'country');
                ->setAttrib('onchange', 'javascript goes here that will set textbox to visible'
$textbox = $this->createElement('text',’textbox’);
            $textbox->setAttrib('style', 'display:none;')
            ->setAttrib('id', 'country');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM