View Full Version : changing text in table elements

05-23-2005, 07:01 AM
Hello all,

I've done a fair amount of searching for an answer to this question but to no avail, so I thought I'd post here for some advice.

I was wondering if it was possible for JavaScript to change the text in a table cell based upon an 'onchange' or 'onclick' event? For example, let's say I have a simple table with two elements with text in each cell, ie:

<tr><td>Text 1</td><td>Text 2</td></tr>

What I'd like to do is have a JavaScript which writes text to one cell or the other based upon an onchange or onclick event on the page....is this possible, and if so, may I ask for a sample of the code required to do this.

Thanks for any assistance!

05-23-2005, 08:53 AM
The easiest way is to use innerHTML.

<tr><td id="cell">Text 1</td><td>Text 2</td></tr>

<input type="button" value="Set" onclick="document.getElementById('cell').innerHTML='blah'" />

05-23-2005, 04:44 PM
Thanks glenngv,

That looks like a nice straight-forward solution; I'll give it a try tonight.


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum