www.webdeveloper.com
Results 1 to 4 of 4

Thread: problem with onclick

  1. #1
    Join Date
    Apr 2009
    Posts
    2

    problem with onclick

    Hello, I'm a newbie with javascript, and I have the following problem:
    I created a table a table, and when I click on a certain row, I would like that it prints out a certain message in this row.

    I should look like this:

    <table>
    <tr>
    <td onclick="printmessage"> </td>
    </tr>
    </table>

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    onclick="this.innerHTML='message';"

  3. #3
    Join Date
    May 2008
    Posts
    6
    hi
    please check the below code if u want the message in the same row with data.
    function printmessage(obj){

    var childRows = document.getElementById("sample").rows;
    for(i=0;i < childRows.length;i++)
    {
    if(childRows[i].id == obj.id){
    cell = childRows[i].insertCell();
    cell.innerHTML ="You are selected " +(i+1)+ " row";
    }
    }

    }

    and in the form it should be like

    <table id="sample">
    <tr id="1" onclick="javascriptrintmessage(this);">
    <td >Row 1
    </td>
    </tr >
    <tr id="2" onclick="javascriptrintmessage(this);">
    <td>Row 2
    </td>
    .....
    </tr>
    </table>

  4. #4
    Join Date
    Apr 2009
    Posts
    2
    Thanks, this is what I'm looking for, but i still have a problem that I forgot to mention.
    I want to catch the data on a button with a click, and then after clicking in a row, I want to print this data.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles