|
|||||||
New to SitePoint Forums? Register here for free!
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
SitePoint Enthusiast
![]() Join Date: Aug 2006
Posts: 32
|
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 |
|
enjoiningOfTruth++;
![]() ![]() ![]() Join Date: Aug 2006
Location: Turkey ( Türkiye )
Posts: 239
|
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 |
|
SitePoint Enthusiast
![]() Join Date: Aug 2006
Posts: 32
|
Thanks a lot i'm searching this over a week now. Thak You
|
|
|
|
|
|
#5 |
|
enjoiningOfTruth++;
![]() ![]() ![]() Join Date: Aug 2006
Location: Turkey ( Türkiye )
Posts: 239
|
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 01:56.. |
|
|
|
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
| Display Modes | |
|
|
|
All times are GMT -7. The time now is 05:40.










Linear Mode
