SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    send onclick value to table cell

    i have a table with 50 cells with difrent id's and i have an other table with predefined values in them i need to send the value of the second table cells to the first table cells with onclick. is there a function for this?

  2. #2
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
     
    <script type="text/javascript">
    
    function writeToCell (a,s) {
    
    var e = document.getElementsByTagName('table');
    e = e[0].document.getElementsByTagName('td');
    e[s].innerHTML = a ;
    
    }
    
    </script>
    <style type="text/css">
    td{ width:50px;height:50px; background-color:yellow;}
    </style>
    
    <table><tr>
    <td>  </td>
    <td>  </td>
    <td>  </td>
    <td>  </td>
    <td>  </td>
    <td>  </td>
    </tr></table>
    
    <table><tr>
    <td onclick="writeToCell (this.innerHTML,0)"> aaa </td>
    <td onclick="writeToCell (this.innerHTML,1)"> bbb </td>
    <td onclick="writeToCell (this.innerHTML,2)"> ccc </td>
    <td onclick="writeToCell (this.innerHTML,3)"> ddd </td>
    <td onclick="writeToCell (this.innerHTML,4)"> eee </td>
    <td onclick="writeToCell (this.innerHTML,5)"> fff </td>
    </tr></table>

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2006
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot i'm searching this over a week now. Thak You

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, I have a related demo

  5. #5
    SitePoint Addict
    Join Date
    Aug 2006
    Posts
    266
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dblack
    I noticed the above code did not work in Mozilla. So I wrote the following code.
    You can use the following code. Because this is working in Mozilla, Opera and Internet Explorer.
    Code:
      
    <script type="text/javascript">
    
    function writeToCell (a,s) {
    
    var e = document.getElementById(s);
    e.innerHTML = a.innerHTML ;
    
    }
    
    </script>
    <style type="text/css">
    td{ width:50px;height:50px; background-color:yellow;}
    </style>
    
    <table><tr>
    <td id="t0">  </td>
    <td id="t1">  </td>
    <td id="t2">  </td>
    <td id="t3">  </td>
    <td id="t4">  </td>
    <td id="t5">  </td>
    </tr></table>
    
    <table><tr>
    <td onclick="writeToCell (this,'t0')"> aaa </td>
    <td onclick="writeToCell (this,'t1')"> bbb </td>
    <td onclick="writeToCell (this,'t2')"> ccc </td>
    <td onclick="writeToCell (this,'t3')"> ddd </td>
    <td onclick="writeToCell (this,'t4')"> eee </td>
    <td onclick="writeToCell (this,'t5')"> fff </td>
    </tr></table>
    Last edited by muazzez; Jan 10, 2007 at 02:56.


Bookmarks

Posting Permissions

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