form_dropdown with image

Is there any way for me to populate form_dropdown items with image besides ?
For eg: I have a Language Translation drop down menu. I want to put a Flag besides each of the language .. thanks in advance

I tried it once but it's not possible. the option tag only takes text as content. You could do it using javascript to mimic a select tag.

I was able to accomplish what you are dicussing with CSS.

With something like:

<style type="css/text">
#tester option{
     padding-left: 25px;
     background: transparent url(path/to/icon.png) top left no-repeat
<select id="tester">
      <option value="1">Option 1</option>
      <option value="2">Option 2</option>
      <option value="3">Option 3</option>
      <option value="4">Option 4</option>

Give it a try, I hope it helps!

Then you only have one image or you would have to do something like
&lt;style type="css/text"&gt;
#tester .option1{
     padding-left: 25px;
     background: transparent url(path/to/icon1.png) top left no-repeat
#tester .option2{
     padding-left: 25px;
     background: transparent url(path/to/icon2.png) top left no-repeat
<select id="tester">
      <option value="1" class="option1">Option 1</option>
      <option value="2" class="option2">Option 2</option>
      <option value="3" class="option3">Option 3</option>
      <option value="4" class="option4">Option 4</option>
Which is not very maintainable. But if you use style it would work.
&lt;?php foreach($countries as $country){ ?&gt;
<option value="&lt;?php echo $country['value']; ?&gt;"&lt;?php echo $country['attr']; ?&gt;>&lt;?php echo $country['value']; ?&gt;</option>
&lt;?php } ?&gt;
where $country['attr'] would output something like
style="background: transparent url(path/to/flag.png) top left no-repeat;"

Yes, what I posted was meant to be strictly a skeleton for how to proceed. You're correct that to have a solid solution to this it would require quite a bit more logic.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.