Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Get Table Cell value using Javascript

Reply
Thread Tools

Get Table Cell value using Javascript

 
 
=?Utf-8?B?Qw==?=
Guest
Posts: n/a
 
      04-23-2007
How do I get the text from my cell e..g. <td>Test Text</td>



var elTableCells = elTableRow.getElementsByTagName("td");

alert(elTableCells[0].innerText);

 
Reply With Quote
 
 
 
 
Ray Costanzo
Guest
Posts: n/a
 
      04-23-2007
You answered your own question. What you're doing below should work, as
long as elTableRow is defined prior to that call. Sample:

<html><body>
<script type="text/javascript">
function test() {
var elTableRow = document.getElementById("somerow");
var elTableCells = elTableRow.getElementsByTagName("td");
alert(elTableCells[0].innerText);
}
</script>
<button onclick="test()">click me</button>
<table>
<tr id="somerow">
<td>cell 1</td>
<td>cell 2</td>
</tr>
</table>
</body>
</html>




"C" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> How do I get the text from my cell e..g. <td>Test Text</td>
>
>
>
> var elTableCells = elTableRow.getElementsByTagName("td");
>
> alert(elTableCells[0].innerText);
>


 
Reply With Quote
 
 
 
 
=?Utf-8?B?TWFuaXNoIEJhZm5h?=
Guest
Posts: n/a
 
      04-23-2007
Hi,
Try this code:
<td id ="tdname">Test Text</td>
alert(document.forms[0].getElementsByTagId("tdname").innerText);
you need to take care of case-sensitivity as javascript is
case-sensitive(that i have not taken care in above code)
Hope this helps
--
If my answer helped you,then please do press Yes below.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



"C" wrote:

> How do I get the text from my cell e..g. <td>Test Text</td>
>
>
>
> var elTableCells = elTableRow.getElementsByTagName("td");
>
> alert(elTableCells[0].innerText);
>

 
Reply With Quote
 
Leda Wu
Guest
Posts: n/a
 
      04-30-2007
If the cell is a dropdown list, how can I get the selectedIndex value by this approach?
Thank you very much!

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
Reply With Quote
 
Leda Wu
Guest
Posts: n/a
 
      04-30-2007
If the cell is a dropdown list, how can I get the selectedIndex value by this approach?
Thank you very much!

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
Reply With Quote
 
oceans_ripple_light oceans_ripple_light is offline
Junior Member
Join Date: Jul 2012
Posts: 1
 
      07-25-2012
You can get cell value with JS even when click on the cell:

Code:
.......................
    
          <head>
               
            <title>Search students by courses/professors</title>
             
            <script type="text/javascript">
              
            function ChangeColor(tableRow, highLight)
            {
               if (highLight){
            	   tableRow.style.backgroundColor = '00CCCC';
               }
            
            else{
            	 tableRow.style.backgroundColor = 'white';
                }   
          }
        
          function DoNav(theUrl)
          {
          document.location.href = theUrl;
          }
          </script>
        
        </head>
        <body>
        
             <table id = "c" width="180" border="1" cellpadding="0" cellspacing="0">
            
                    <% for (Course cs : courses){ %>
              
                    <tr onmouseover="ChangeColor(this, true);" 
                        onmouseout="ChangeColor(this, false);" 
                        onclick="DoNav('http://localhost:8080/Mydata/ComplexSearch/FoundS.jsp?courseId=<%=cs.getCourseId()%>');">
                 
                         <td name = "title" align = "center"><%= cs.getTitle() %></td>
                               
                    </tr>
                   <%}%>
        
        ........................
        </body>
I wrote the HTML table in JSP.
**Course** is is a type. For example Course cs, cs= object of type Course which had 2 attributes: id, title.
**courses** is an ArrayList of Course objects.

The HTML table displays all the courses titles in each cell. So the table has 1 column only:
Course1
Course2
Course3
......
Taking aside:

Code:
 onclick="DoNav('http://localhost:8080/Mydata/ComplexSearch/FoundS.jsp?courseId=<%=cs.getCourseId()%>');"
This means that after user selects a table cell, for example "Course2", the title of the course- "Course2" will travel to the page where the URL is directing the user:
Code:
http://localhost:8080/Mydata/ComplexSearch/FoundS.jsp
. "Course2" will arrive in FoundS.jsp page. The identifier of "Course2" is courseId. To declare the variable courseId, in which CourseX will be kept, you put a "?" after the URL and next to it the identifier.
It works.
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
get Table cell value Sunny Javascript 3 10-20-2008 04:58 PM
Get Table Cell Value using Javascript =?Utf-8?B?Qw==?= ASP .Net 1 04-23-2007 01:10 PM
Get 2nd cell value from table row? harry Javascript 2 07-22-2004 01:34 PM
How do I have a table cell fetch another page to display within the cell? Phillip Roncoroni HTML 14 04-05-2004 05:58 PM
get a table cell value yukatan Javascript 2 11-06-2003 11:52 PM



Advertisments