Solved

how to get data from HTML Table using javascript

Posted on 2009-05-05
2
2,247 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

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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 how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

910 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

25 Experts available now in Live!

Get 1:1 Help Now