Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing cell attributes via a button click.

Status
Not open for further replies.

rr236

IS-IT--Management
Oct 23, 2000
37
GB
Hi,

I'm, sure this can be done, but it's not blindingly obvious (to me anyway).

How can you change a table cell attribute (for example the bgcolor attribute) via a click on a button. I know this can be done with mouseovers, but I need this to be done via a button click.

Any ideas would be greatly appreciated.

thanks
rr236
 
<input type=button value=&quot;click me !&quot; onclick=&quot;javascript:change_bg_color()&quot;>

where change_bg_color() is the jscript function to change your table cell attribute

it's juste the same as &quot;onmouseover&quot; but you use &quot;onclick&quot;
 
Thanks iza,

but I can't figure out HOW to address the actual cell within a tablefield.

eg. imagine there is a table with 2 columns and 3 rows.

How do you change the bgcolor for the cell defined as column 2, row 3.

In other words, what code actually goes in the function
change_bg_color() called by the onclick event for the button?

thanks in advance
rr236

 
function changeBgColor(obj,color)
{
obj.style.backgroundColor=color
}

where obj is the object id of the table cell and color is a string with a color value ('red','green','#ff00cc',whatever) jared@aauser.com
 
> give your cells ids then do what jared said

No thank you. I would prefer this:

<where 'nrow' and 'ncell' are valid table row and column indecies>

document.all(&quot;mytable&quot;).rows(nrow).cells(ncell).style.backgroundColor = &quot;#ff9999&quot;;

Unless of course your cells need ids for some other reason.

&quot;But, that's just my opinion... I could be wrong&quot;.
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top