473,386 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

get Table cell value

Hi,

If I have an Html like that:
<input id="testObjectId" type="text" value="1" />
<table>
<tr>
<td>25</td>
<td>Sunday</td>
<td>0</td>
<td>518</td>
</tr>
</table>

How Can I use "a href" to put value in the Textbox by clicking on
table cell.
somehing like:
<td><a
href="javascript:document.getElementById(testObjec tId).value='25'>25</
a></td>
Should work:
But this is writing on the screen in a new window instead of a
Textbox.

What to do?
Oct 20 '08 #1
3 5852
Sunny wrote:
<td><a
href="javascript:document.getElementById(testObjec tId).value='25'>25</
a></td>
Put the code in an onclick handler
<td onclick="document.getElementById('someId').value =
this.firstChild.nodeValue;">25</td>
or if you need the link
<td><a href="#" onclick="document.getElementById('someId').value =
this.firstChild.nodeValue; return false;">25</a></td>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 20 '08 #2
On Oct 20, 12:02 pm, Martin Honnen <mahotr...@yahoo.dewrote:
Sunny wrote:
<td><a
href="javascript:document.getElementById(testObjec tId).value='25'>25</
a></td>

Put the code in an onclick handler
<td onclick="document.getElementById('someId').value =
this.firstChild.nodeValue;">25</td>
or if you need the link
<td><a href="#" onclick="document.getElementById('someId').value =
this.firstChild.nodeValue; return false;">25</a></td>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Thanks martin It works.
<table>
<tr>
<td>25</td>
<td>Sunday</td>
<td>0</td>
<td>518</td>
</tr>
</table>
But what if, I want to put a href on Sunday & Want to display 25 in
textbox on click.
Oct 20 '08 #3
Sunny wrote:
But what if, I want to put a href on Sunday & Want to display 25 in
textbox on click.
Well then assign the string literal '25' as you had in your original
code. Or get fancy with

<table>
<tr>
<td>25</td>
<td onclick="document.getElementById('someId').value =
this.parentNode.cells[this.cellIndex - 1].firstChild.nodeValue;">Sunday</td>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 20 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Seth | last post by:
How can I hide an entire row of a table if one of the cells in that row is equal to a value drop down box value. My goal is to have a filtered table so that each cell in each row determines if...
2
by: David Bradbury | last post by:
I currently have an iframe on a webpage into which users can insert content. They can further customise the text as I've included buttons such as Bold, Italic, Bullet point etc. This is done along...
1
by: Thanks | last post by:
I have a routine that is called on Page_Init. It retrieves folder records from a database which I display as Link Buttons in a table cell. I set the table cell's bgcolor to a default color (say...
2
by: dschectman | last post by:
This appears to be a feature of IE JavaScript. I am running IE 6.0 with the latest patches from Microsoft. Are there any workarounds other than re-coding the source HTML to place all the...
7
by: slitvinov | last post by:
I am learning Relax NG. The problem is that I cannot figure out how to make a schema for a table. In my case I would like to make a table with any name of child elements (columns) but columns...
6
by: anirban.anirbanju | last post by:
hi there, i've some serious problem to add rows dynamically in a table. my table contains 5 cell. | check | from_value | to_value | color_text | color_value |...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
3
by: azegurb | last post by:
hi I have just took from internet dinamic table. this table is dynamic and its rows dynamically can be increased. but i would like how create SUM function that automatically sums each added row...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.