...

View Full Version : changing text in table elements



breaker
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:

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

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!
Breaker.

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

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

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

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

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

Cheers!
Breaker



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum