Solved

how to get a control in a data cell using java script

Posted on 2014-07-25
1
137 Views
Last Modified: 2014-07-27
Suppose my Java Script is iterating through a table row and cell
at a time. Meaning accessing the contents of each <td> cell.

I know that I can access the contents of the cell using innerhtml. That works
good when there is data in the cell.

However what if there is a control in the cell. Like a label control for example.
How would I access that control, so that I can get the id of the control?

You see when the java script is iterating through each cell, it has no idea if the
data in each cell is a control or just data, like "Hello World".



<table>
<tr>
<td>Hello World</td>
</tr>

<tr id="outter">
<td id="inner">
<Label id="Label1" Text="Label Control" runat="server"/>
</td>
</tr>

</table>
0
Comment
Question by:brgdotnet
1 Comment
 
LVL 63

Accepted Solution

by:
Zvonko earned 310 total points
ID: 40219769
What about this:
<htm>
<head>
<title>Zvonko &#42;</title>
</head>
<body>
<table>
<tr>
<td>Hello World</td>
</tr>
<tr id="outter">
<td id="inner">
<Label id="Label1" Text="Label Control" runat="server"/>
</td>
</tr>
</table>
<script>
var theTab = document.getElementsByTagName("table")[0];
var theCell = theTab.rows[1].cells[0];
var theLabels = theCell.getElementsByTagName("label");
alert(theLabels[0].id);
</script>
</body>
</html>

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Find out all repos that a user is most active on Github 1 26
Use "if not" in a condition 2 18
Use Mid in Html 6 21
Table doesn't show the lines! 3 23
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question