Dropdown List Add Aditional Options To Each Option

This is my code


<?php echo CHtml::dropDownList

			('lang', 'hr',

				array('hr'=>'Hrvatski', 'en'=>'English', 'de'=>'Deutsch', 'serb'=>'Srpski', 'bih'=>'BiH', 'slo'=>'Slovenski'),

				array('onClick'=>'izaberijezik()', 'hr'=>array())

			); ?>

And it works until


'hr'=>array()

. Cause I would like to generate option with data-image value


<option value="hr" data-image="/images/flags/Croatia.png"  >Hrvatski</option>

check this wikki link. you will get a complete idea what you have to do.

and specially this one…




DOCUMENTATION Take the Tour Tutorials Class Reference Wiki Screencasts Resources

htmlOptions explained for various controls.  

report it160

12 followers


 

Most controls that are rendered by CHtml have an argument called $htmlOptions. This argument is an array that holds the attributes of the HTML element. For example the following code:


<?php echo CHtml::link("Yii","http://www.yiiframework.com",array("style"=>"color: orange;")); ?>

Will render this link:


<a style="color: orange;" href="http://www.yiiframework.com">Yii</a>

Some tags are more complicated, for example a drop down list is composed of multiple tags:


<select>

 <option>

 <option>

</select>

To get attributes onto the options, add a sub-array called "options" to your htmlOptions. For example to color each item in your drop down a different color this code:


$items = array("1" => "first", "2" => "second");

$options["options"] = array("1"=>array("style" => "color:red"), "2"=>array("style"=>"color:blue"));

echo CHtml::dropDownList("myDropDown", null, $items,$options);

Produces this html:


<select name="myDropDown" id="myDropDown"> 

<option value="1" style="color:red">first</option> 

<option value="2" style="color:blue">second</option> 

</select>



i hope it will help you a lot :)

That helped. thank you very much

that’s great ;)