Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    changing text in table elements

    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.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,043
    Thanks
    0
    Thanked 251 Times in 247 Posts
    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'" />

  • #3
    New to the CF scene
    Join Date
    May 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks glenngv,

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

    Cheers!
    Breaker


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •