Sunday, January 18, 2009

How to change the color of the selected item of drop downlist

change the color of the selected item
<script language="javascript">
function chgColor(evt)
evt.options[evt.selectedIndex].style.background = 'red';
for(i=0; i< evt.options.length;i++)
if(i != evt.selectedIndex)
evt.options[i].style.background = '';
<select onchange="chgColor(this)">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="1">5</option>
<option value="2">6</option>
<option value="3">7</option>
<option value="4">8</option>
<option value="1">9</option>
<option value="2">0</option>

No comments:

Creative Commons License
Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.