By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,814 Members | 2,162 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,814 IT Pros & Developers. It's quick & easy.

Table row background color change when button click

P: 2
Hi,

Can anyone can tell me how to change a table row background color when I click a button? most of the tutorial I found add the event on the TR onclick event, but that not I want.

It is possible? I really appreciate any help.

can you give me a script

thanks in advance....

iceburn17
Sep 14 '06 #1
Share this Question
Share on Google+
1 Reply


P: 2
I finally solve my problem, thank for the help, and now I want to share it with others; here are the script:

var preEl ;
var orgBColor;
var orgTColor;
function HighLightTR(backColor,textColor){
if(typeof(preEl)!='undefined') {
preEl.bgColor=orgBColor;
try{ChangeTextColor(preEl,orgTColor);}catch(e){;}
}

var el = event.srcElement;
if(el!='tr')
{
el = el.parentElement;
el = el.parentElement;
}
orgBColor = el.bgColor;
orgTColor = el.style.color;
el.bgColor=backColor;

try{ChangeTextColor(el,textColor);}catch(e){;}
preEl = el;
}

function ChangeTextColor(a_obj,a_color){ ;
for (i=0;i<a_obj.cells.length;i++)
a_obj.cells(i).style.color=a_color;
}

To use it just add it in the onclick event of the button.

Actually I find this script on the net, I just made some modification to it so that when I click a button it will change the color of the row. And also it will not work if your using image as your button, I don't know why, but if your using a regular button it will work fine.

I hope I may able to help someone....


iceburn17

Hi,

Can anyone can tell me how to change a table row background color when I click a button? most of the tutorial I found add the event on the TR onclick event, but that not I want.

It is possible? I really appreciate any help.

can you give me a script

thanks in advance....

iceburn17
Sep 15 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.