Solved

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

Posted on 2014-07-25
1
134 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now