简体   繁体   中英

How to assign id field in codeigniter for form_dropdown

i am stuck with ,ie how to assign id field to form_drop-down this is my code for drop-down list

<?php echo form_dropdown('max', range(19, 90)); ?>

i am trying this but it don't work for another drop down

<?php $minage = array('id' => 'minAge');

echo form_dropdown('min', range(18, 90),$minage); ?>

i dont know where i am wrong

You need construct the id as a string not as a array, and it´s the fourth parameter, not the third (the third parameter is the default value)

See the example in docs:

$options = array(
              'small'  => 'Small Shirt',
              'med'    => 'Medium Shirt',
              'large'   => 'Large Shirt',
              'xlarge' => 'Extra Large Shirt',
            );

$js = 'id="shirts" onChange="some_function();"';

echo form_dropdown('shirts', $options, 'large', $js);

"Lets you create a standard drop-down field. The first parameter will contain the name of the field, the second parameter will contain an associative array of options, and the third parameter will contain the value you wish to be selected. You can also pass an array of multiple items through the third parameter, and CodeIgniter will create a multiple select for you."

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