Jason28 Posted July 4, 2009 Share Posted July 4, 2009 Hello, I am using a function I found that changes the background color of a <tr> column when a checkbox is unchecked. I would like to make one small change... currently you can only use colors such as "red, blue, green, etc." to submit to the function. I would like to be able to use hexi colors like #FF0000 and such. Here is the code: <script type="text/javascript"> //var list = document.getElementsByTagName("tbody")[0].getElementsByTagName("tr"); function toggleColour(obj,col) { col=col||'transparent' var row = findParentRow(obj); if (!row.col) row.col=row.style.backgroundColor; row.style.backgroundColor = obj.checked ? row.col : col; } function findParentRow(obj) { var tmp = obj.parentNode; if(tmp.nodeName.toLowerCase() != "tr") { tmp = findParentRow(tmp); } return tmp; } </script> <table> <tr style="background-color:white;"> <td class="bigtext"><input type="checkbox" value="1" name="chk[1]" checked="checked" onClick="toggleColour(this,'red');" /></td> <td class="bigtext">test 1</td> </tr> <tr style="background-color:white;"> <td class="bigtext"><input type="checkbox" value="1" name="chk[2]" checked="checked" onClick="toggleColour(this,'red');" /></td> <td class="bigtext">test 2</td> </tr> </table> You can see in the html where onClick="toggleColour(this,'red') passes the color red, I would like to use html hexi colors in that field instead of just 'red'. It doesn't seem to work if you just add a hexi color there. Thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 5, 2009 Share Posted July 5, 2009 Works just fine with a hex color, just preface it with the pound character - "#cecece" Quote Link to comment Share on other sites More sharing options...
Jason28 Posted July 5, 2009 Author Share Posted July 5, 2009 Very weird, it didn't work the first time I tried it? That is why I created this topic since I was stumped on why it wouldn't work. Oh well it is fine now, thanks. 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.