Go Back   SitePoint Forums > Forum Index > Program Your Site > JavaScript
Newsletter FAQ Members List Calendar Mark Forums Read

New to SitePoint Forums? Register here for free!

SitePoint Sponsor
 
Reply
 
Thread Tools Display Modes
Old Jan 9, 2007, 07:49   #1
dblack
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?
dblack is offline   Reply With Quote
Old Jan 9, 2007, 09:04   #2
muazzez
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>
muazzez is offline   Reply With Quote
Old Jan 9, 2007, 09:10   #3
dblack
SitePoint Enthusiast
 
Join Date: Aug 2006
Posts: 32
Thanks a lot i'm searching this over a week now. Thak You
dblack is offline   Reply With Quote
Old Jan 9, 2007, 09:26   #4
MikeFoster
I'll take mine raw
silver trophy
 
MikeFoster's Avatar
 
Join Date: Dec 2002
Location: Alabama, USA
Posts: 2,562
Hi, I have a related demo
__________________
Cross-Browser.com, Home of the X Library
MikeFoster is offline   Reply With Quote
Old Jan 9, 2007, 11:14   #5
muazzez
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..
muazzez is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread | Next Thread »

Thread Tools
Display Modes

 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

 
Forum Jump


All times are GMT -7. The time now is 05:40.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright 1998-2009, SitePoint Pty Ltd. All Rights Reserved