Solved

How to access the html table data

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Angular- another way of coding hide and display 3 40
Animated .jpg? 13 61
Angular - disable input field on page load 4 14
insert text field data into html script 13 27
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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 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…

895 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