Solved

How to access the html table data

Posted on 2011-03-18
6
116 Views
Last Modified: 2013-11-19
I want to access the html data and wnat to pass it through ajax to a controller.i don't know how to access the table data.
0
Comment
Question by:amitabhg
6 Comments
 
LVL 12

Expert Comment

by:enachemc
ID: 35163245
give an id to the table (you can give an id to any tag)
then use :
var tbl = document.getElementById('myTblId');
tbl.rows[0].cells[0];//this accesses first cell of first row
0
 
LVL 20

Accepted Solution

by:
Proculopsis earned 500 total points
ID: 35163282

Do you mean something like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_26895670.html</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">

$( function() {

  var data = [];

  $("#my-table td").each( function() {
    data.push( $(this).text() );
  });

  $( "#post-me" ).text( data.toString() );

});

</script>
</head>
<body>

<table id="my-table" border="1">
<tr><td>1</td><td>a</td><td>b</td></tr>
<tr><td>2</td><td>p</td><td>q</td></tr>
<tr><td>3</td><td>x</td><td>y</td></tr>
</table>

Post this: <span id="post-me"></span>

</body>
</html>

Open in new window

0
 

Expert Comment

by:Dinesh Kumar
ID: 35163301
Are  you working in MVC?
0
 

Author Comment

by:amitabhg
ID: 35164172
Yes i am working in mvc.
@Proculopsis:thanks for the solution
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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 the basics of jQuery including how to code hide show and toggles. 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…

792 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