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? Link to comment https://forums.phpfreaks.com/topic/78748-new-option/ 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> Link to comment https://forums.phpfreaks.com/topic/78748-new-option/#findComment-398545 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. Link to comment https://forums.phpfreaks.com/topic/78748-new-option/#findComment-398553 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.