0

I want to get all <input>, select the name and all data-attributes which are inside the column in the table. I'm stuck, my table loop starts from 5th row instead of starting from 2nd;

var rowNo = jQuery(this).attr("data-row"); jQuery("#example1 table tbody").find('tr').each(function (key, value) { jQuery(this).find('td').each(function (key, val) { var tName = jQuery(this).find('input,select').attr('name'); console.log(tName); }); }); 

and

<div id="example1"> <table id="Invoice"> <tbody> <tr class="header_table"> <th></th> <th>InvoiceNo</th> <th>InvoiceDate</th> </tr> <tr class="even" name="tr_2"> <td><i class="fa fa-trash-o icon-class" data-row="2"></i></td> <td><input data-cols="1" data-row="2" name="input_[2][InvoiceNo]" type="text"></td> <td><input data-cols="2" data-row="2" name="input_[2][InvoiceDate]" type="text"></td> </tr> ..... ... </tbody> </table> </div> 

output

"select_[5][Supplier]" "input_[5][Description]" "input_[5][Serial]" "select_[5][AssetType]" "select_[5][PurchasePrice]" "input_[5][PONumber]" 

tested my the html table

 jQuery("table").find('tr').each(function(key,value){ jQuery(this).find('th,td').each(function(key1,val){ console.log(key1); }); }); 

I get output as:

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 . ... ... .. 
9
  • fix your html. you don't write end tag of your first tr. Commented May 24, 2015 at 11:31
  • it just typo in question i even cannot loop from column 1 the table looping start from 3 Commented May 24, 2015 at 11:34
  • It's completely unclear what you want to achieve. Commented May 24, 2015 at 11:42
  • i'm not able to loop through table correctly Commented May 24, 2015 at 11:43
  • @MayuriS, see here (jsfiddle.net/2296gdru). after fix your html it works fine. Commented May 24, 2015 at 11:47

1 Answer 1

2

From the comments

i want retrieve all td data from table

I translate that as "I want to have a collection of all data in all input fields in my table".

This could look as simple as:

var data = {}; jQuery("#example1 table input").each(function () { data[this.name] = this.value; }); 

This produces an object with keys and values for further processing.

If the data is directly for transmission to a server, it becomes as simple as

var data = jQuery("#example1 table").serialize(); $.post("url", data); 
Sign up to request clarification or add additional context in comments.

2 Comments

@MayuriS Notice the difference between what you want to do and what you want to achieve? Next time you ask a question here, try to concentrate more on the desired result you want to have in the end (and less on the activities you think you need for that).
yes sure hey once again thanks for showing example of data transmission

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.