Solved

How to access the html table data

Posted on 2011-03-18
6
112 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
Comment Utility
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
Comment Utility

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
Comment Utility
Are  you working in MVC?
0
 

Author Comment

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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
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…

762 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

11 Experts available now in Live!

Get 1:1 Help Now