Solved

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

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

785 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