Solved

How to access the html table data

Posted on 2011-03-18
6
119 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
[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
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

728 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