0

I am trying to display images in dropdown. I have code like this

<?php
    $sql2 = "SELECT * FROM item_category";
    $query2 = mysql_query($sql2);
?>

<select name="category" onChange="showItems(this);">
    <option value="">Select Product Category</option>
    <?php while ($rs2 = mysql_fetch_array($query2)) { ?>
        <option value="<?php echo $rs2["item_id"]; ?>">
            <img src="../upload/category/<?php echo $rs2["image"]?>">
        </option>
    <?php } ?>
</select>

But it displays blank. Can you please advise me how to do it?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Akshay Kumar
  • 1
  • 1
  • 2

3 Answers3

0

html tags (i.e. img) are not supported within the option tag

Consider using jquery-ui selectmenu with custom rendering.

Here you can find the link with some example and API doc. http://jqueryui.com/selectmenu/#custom_render

or have a look at this post using msDropDown()

Community
  • 1
  • 1
0

The only way for doing it would be by using some jQuery plugins.This is a great plugin that might help you solve your issue mate.Do have a look on it.There are lot of other plugins too mate.. :)

JavaScript Image Dropdown

Nibin
  • 3,922
  • 2
  • 20
  • 38
  • There are plugins besides jQuery that can handle this, so I wouldn't call it the "only" way. But the gist of what you are saying is true... this is not possible with an HTML-only solution. – JDB Jan 15 '15 at 14:22
0

I think there is no direct way for doing it. Probably you have to generate a new html element along with css and javascript, against the values in the select / dropdownlist and design it like a dropdown. Define events for that works on that are similar to dropdown. Then only you can add images to your dropdown. There are lots of plugins available over the net, but i can't have access at my work area.

For Your reference you can use the link http://designwithpc.com/Plugins/ddSlick#demo. Consider it as an example.

Please do add a reference in case you find a lightweight and responsive plugin in case you find it. Good luck .....

Mayank
  • 1,351
  • 5
  • 23
  • 42