Azazia Software Knowledgebase
Search:     Advanced search
Browse by category:
Contact Us

Adding a background color for each row of an html select drop down (pull down) menu.

Add comment
Views: 542
Votes: 0
Comments: 0
Posted: 14 Sep, 2009
by: Patridge B.
Updated: 14 Sep, 2009
by: Patridge B.
Using a standard Select drop down menu like the following:


<select name='test'>
 <option selected>fender</option>
<option>gibson</option>
<option>les paul</option>
<option>jackson</option>
</select>


To change the background color or font for EACH ROW you would do the following:

<select name='test'>
<option selected style='background-color:#333333;color:#FFFFFF'>fender</option>
<option style='background-color:#FF0000;color:#FFFFFF;font-weight:bold'>gibson</option>
<option style='background-color:#FFCCEE;font-weight:bold'>les paul</option>
<option style='background-color:#9988CC;font-weight:bold;color:FFEEEE'>jackson</option>
</select>


If you wish to use the above using a mysql query, here is an example:

 echo "<td>Legend</td><td><select name=legend>";

         echo "<option selected>-Display Legend-</option>";
         $cq="SELECT unavcolor,unavstat,fontcolor from legend  order by unavstat ASC";
         $res=mysql_query($cq) or die ("$QUERY_ERROR $query");
         while ($row=mysql_fetch_array($res)) {
             extract($row);
             echo "<option style='background-color:$unavcolor;color:$fontcolor'><B>$unavstat</B></option>";
         }// end while
         echo "</select>";
Others in this Category
document Unset HTTP GET Variables in PHP



RSS