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?

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

Thanks a lot i’m searching this over a week now. Thak You

Hi, I have a related demo :slight_smile:

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.

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