View Full Version : SELECT onclick
hosdank
08-26-2008, 04:42 PM
Can I have a onclick event on a option tag that changes the background of that option? If so, how do I do it? Thanks :)
jackbenimble4
08-26-2008, 08:03 PM
I believe the CSS background property for option elements isn't supported by all browsers. I remember testing this recently... It works in Firefox 3.0 for sure, but I'm pretty sure the property is ignored in all version of Internet Explorer.
clueful
08-26-2008, 08:09 PM
Can I have a onclick event on a option tag that changes the background of that option? If so, how do I do it? Thanks :)Presumably you mean background colour. You can do something like this:
<select onchange="this.options[this.selectedIndex].style.backgroundColor='#0f0'">but results vary.
hosdank
08-27-2008, 01:45 PM
Yeah, but the thing is I want all the other backgrounds to change back to what they were. Thanks anyway :)
clueful
08-27-2008, 03:07 PM
Yeah, but the thing is I want all the other backgrounds to change back to what they were. Thanks anyway :)Yes I thought you might.
<select onchange="setOptionColour(this,'#0f0')">
........
<script type="text/javascript">
function setOptionColour(box, clr)
{
for(var i=0, len=box.options.length; i<len; i++)
box.options[i].style.backgroundColor=(i==box.selectedIndex)?clr:"";
}
</script>
hosdank
08-27-2008, 03:22 PM
Thanks so much :):):)
codeexploiter
08-28-2008, 03:20 AM
But if you check the display of a background-color based options in a select list through Firefox and IE, you'll get two different things
magicyte
08-28-2008, 10:42 PM
You can use the .select() object to select text in a textfield, jsut for later use.
-magicyte
Powered by vBulletin® Version 4.2.2 Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.