Solved

How to access the html table data

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Javascript object functions help 1 19
Timer on div 5 26
how can i break an array into a couple 5 26
close pop up windows when logout or main window closes 17 56
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…

697 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