?
Solved

how to get data from HTML Table using javascript

Posted on 2009-05-05
2
Medium Priority
?
2,311 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 63

Accepted Solution

by:
Zvonko earned 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
Suggested Courses

764 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