form_dropdown with image

#1
[eluser]cinewbie81[/eluser]
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

#2
[eluser]xwero[/eluser]
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.

#3
[eluser]jcopling[/eluser]
I was able to accomplish what you are dicussing with CSS.

With something like:

Code:
<style type="css/text">
#tester option{
     padding-left: 25px;
     background: transparent url(path/to/icon.png) top left no-repeat
}
</style>
<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>
</select>

Give it a try, I hope it helps!

#4
[eluser]xwero[/eluser]
Then you only have one image or you would have to do something like
Code:
&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
}
&lt;/style&gt;
<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>
</select>
Which is not very maintainable. But if you use style it would work.
Code:
&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
Code:
style="background: transparent url(path/to/flag.png) top left no-repeat;"

#5
[eluser]jcopling[/eluser]
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.