Solved

how to get data from HTML Table using javascript

Posted on 2009-05-05
2
2,261 Views
Last Modified: 2012-05-06
I have a html table with some data. I want to access the 3rd td in the first tr, that is honda, how can I do that, so that I could be able to use in javascript as a variable.
Thank you.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
 
<body>
 <div id="details" class="show">
    <div style="height:155px">
<table border="0" cellspacing="0" cellpadding="0" class="formTbl">
<tr>
        	<td colspan="7">working</td>
         </tr>
  <tr>
    <td valign="top"><strong>cars</strong></td>
    <td valign="top">&nbsp;</td>
    <td valign="top">honda</td>
    <td valign="top"></td>
    <td valign="top"><strong>very fast</strong></td>
    <td valign="top"></td>
    <td valign="top">Reliable </td>
  </tr>
  <tr>
    <td valign="top"><strong> bikes</strong></td>
    <td valign="top"></td>
    <td valign="top">yamaha</td>
    <td valign="top"></td>
    <td valign="top"><strong>very fast</strong></td>
    <td valign="top">&nbsp;</td>
    <td valign="top">careful</td>
  </tr>
</table>
</div>
</div>
</body>
</html>

Open in new window

0
Comment
Question by:mkarthik415
2 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
ID: 24309023
Check this:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Zvonko &#42;</title>
<script>
window.onload=function(){
  var theDiv = document.getElementById("details");
  var theTab = theDiv.getElementsByTagName("table")[0];
  var rows = theTab.rows;
  var theCell = rows[1].cells[2];
  alert(theCell.innerHTML);
}
</script>
</head>
 
<body>
 <div id="details" class="show">
    <div style="height:155px">
<table border="0" cellspacing="0" cellpadding="0" class="formTbl">
<tr>
                <td colspan="7">working</td>
         </tr>
  <tr>
    <td valign="top"><strong>cars</strong></td>
    <td valign="top"> </td>
    <td valign="top">honda</td>
    <td valign="top"></td>
    <td valign="top"><strong>very fast</strong></td>
    <td valign="top"></td>
    <td valign="top">Reliable </td>
  </tr>
  <tr>
    <td valign="top"><strong> bikes</strong></td>
    <td valign="top"></td>
    <td valign="top">yamaha</td>
    <td valign="top"></td>
    <td valign="top"><strong>very fast</strong></td>
    <td valign="top"> </td>
    <td valign="top">careful</td>
  </tr>
</table>
</div>
</div>
</body>
</html>

Open in new window

0
 

Author Closing Comment

by:mkarthik415
ID: 31578218
Thank you
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
bootstrap footer centering and expand problems 7 43
AdminLTE with wordpress 15 64
How to make footer stick to bottom 9 31
Can't get container centered 4 16
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

810 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