When I click on a <td style="background-color:#CCCCFF">, a table's bgcolor will change to the <td>'s bgcolor, a Textbox's bgcolor will change to the <td>'s bgcolor and display the color's value[example=rgb(204, 204, 255)
] .(actually what I want to display is the Hex code)
now, I need to get the value separately (int r = R, int g=G, int b = B). I need get the correct color to set a Html table bgcolor for email purpose.
I've tried to display the value by Textbox1.BackColor.R.ToString(); but it always show "0" value.
xiaobing
Member
152 Points
216 Posts
get RGB value
Dec 04, 2007 03:06 AM|LINK
scenario:
I do below by javascript.
When I click on a <td style="background-color:#CCCCFF">, a table's bgcolor will change to the <td>'s bgcolor, a Textbox's bgcolor will change to the <td>'s bgcolor and display the color's value[example=rgb(204, 204, 255) ] .(actually what I want to display is the Hex code)
now, I need to get the value separately (int r = R, int g=G, int b = B). I need get the correct color to set a Html table bgcolor for email purpose.
I've tried to display the value by Textbox1.BackColor.R.ToString(); but it always show "0" value.
Please help~ Thanks.
part of the the js script:
document.getElementById(Table1).style.backgroundColor = td.style.backgroundColor;
document.getElementById(Textbox1).style.backgroundColor = td.style.backgroundColor;
document.getElementById(Textbox1).value = td.style.backgroundColor;
A1ien51
All-Star
29935 Points
5821 Posts
Re: get RGB value
Dec 04, 2007 04:21 AM|LINK
I have some functions here that will do it for you:
http://radio.javaranch.com/pascarello/2005/05/19/1116513366466.html
Eric
xiaobing
Member
152 Points
216 Posts
Re: get RGB value
Dec 04, 2007 09:02 AM|LINK
Thanks Eric.
You are right, when I test at IE, it display hex code and everything work well.
But I still don't know how to split the rgb value (I don't want it display as "rgb(255, 255, 255)")
When I use color name, it works at both IE and Firefox, but it is not so effective way.