Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Get Table Cell value using Javascript (http://www.velocityreviews.com/forums/t499268-get-table-cell-value-using-javascript.html)

=?Utf-8?B?Qw==?= 04-23-2007 11:42 AM

Get Table Cell value using Javascript
 
How do I get the text from my cell e..g. <td>Test Text</td>



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

alert(elTableCells[0].innerText);


Ray Costanzo 04-23-2007 11:52 AM

Re: Get Table Cell value using Javascript
 
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" <C@discussions.microsoft.com> wrote in message
news:A8F6E507-C56E-467D-B0C1-A39B1FF18BCF@microsoft.com...
> How do I get the text from my cell e..g. <td>Test Text</td>
>
>
>
> var elTableCells = elTableRow.getElementsByTagName("td");
>
> alert(elTableCells[0].innerText);
>



=?Utf-8?B?TWFuaXNoIEJhZm5h?= 04-23-2007 11:58 AM

RE: Get Table Cell value using Javascript
 
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);
>


Leda Wu 04-30-2007 06:38 PM

get table cell value using javascript
 
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

Leda Wu 04-30-2007 06:39 PM

get table cell value using javascript when cell is adropdown list
 
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

oceans_ripple_light 07-25-2012 02:45 PM

Getting value from HTML table with JS
 
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.


All times are GMT. The time now is 11:18 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.