cha0sriderx Posted November 25, 2007 Share Posted November 25, 2007 im using new option() to create options in a combo box, is there anyway i can add a class or just make it so the font color is different? Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 25, 2007 Share Posted November 25, 2007 you can do this through javascript or css. JavaScript Version: <script language="javascript"> function changecolor(selection) { document.getElementById(selection).style.color="red"; } window.onload=function() { changecolor('select1'); } </script> <select id="select1"> <option value="text value">Text Here </select> or.......... <script language="javascript"> function changecolor() { document.getElementsByTagName('select')[0].style.color="red"; } window.onload=function() { changecolor(); } </script> <select> <option value="text value">Text Here </select> CSS Version: <style type="text/css"> SELECT {color:red} </style> <select> <option value="text value">Text Here </select> Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted November 25, 2007 Share Posted November 25, 2007 you could also do this: <script language="javascript"> function changecolor() { var i="0"; var myselection = document.getElementsByTagName('select')[i].style.color='#FF0000'; for(i;i<myselection.length;i++) { document.getElementsByTagName('select')[i].style.color='#FF0000'; } } // Load Event window.onload=function() { changecolor(); } // Error Catching window.onerror=function() { return true; } </script> <select> <option value="text value">Text Here <option value="text value">Text Here <option value="text value">Text Here </select> <select> <option value="text value">Text Here <option value="text value">Text Here <option value="text value">Text Here </select> <select> <option value="text value">Text Here <option value="text value">Text Here <option value="text value">Text Here </select> this javascript version will let you have multiple select/combo boxes with out you having to set the array key for each select menu every time; as in the other javascript, that I created above, that was similar to this one. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.