0

I want to change background color of selected option item in php but i coulnd do that. I only add an indicator(*) to begining of the selected option with bellow code but i am not exactly need that. I need to change text color of selected form item in php.

Adding style="background-color:red" to $a is works.!

<select name="dest">
                            <?php


                            $a='';
                            $sql2 = "select evaperiod from evaluationperiod";
                            $query2 = mysql_query($sql2);

                            if(mysql_num_rows($query2)>0)
                            {
                                $x='20';
                                $guncel='';
                                while($result=mysql_fetch_array($query2))
                                {
                                    $period = $result['evaperiod']; 
                                    if($period==$donemm)
                                    $a=" selected='selected' style='background-color:red'";
                                    if($period==$periodd)
                                    $guncel='*';
                                    else
                                    $a='';
                                    print "<option value='$period'$a>$guncel$x$period</option>";
                                    $guncel='';
                                }   
                            } ?>

                        </select>
Furkan
  • 143
  • 1
  • 12

3 Answers3

1

Append to the $guncel variable this:

style="background:gray"
Patrick Geyer
  • 1,475
  • 13
  • 30
1

append style="background-color:(yourColor)" to $a

Shri
  • 708
  • 3
  • 11
  • 25
-1

Add a CSS styling for selected

option[selected='selected'] {
    background:red;
    font-color: blue;
}
Ashley Medway
  • 6,982
  • 7
  • 48
  • 66
NaigOlraC
  • 9
  • 2