0

I am trying to store my html table data in an array using jQuery. One of the fields contains a dropdown list. The below code works fine but dropdown list data is not fetched. Can someone help?

var myTableArray = [];

$("table#tblClassificationSearchResult tr").each(function () {
    var arrayOfThisRow = [];
    var tableData = $(this).find('td');
    if (tableData.length > 0) {
        tableData.each(function () { arrayOfThisRow.push($(this).text()); });
        myTableArray.push(arrayOfThisRow);
    }
});

2 Answers 2

1

Well, I am not 100% sure, but I think this should work:

var myTableArray = [];

$("table#tblClassificationSearchResult tr").each(function() {
  var arrayOfThisRow = [];
  var tableData = $(this).find('td');
  if (tableData.length > 0) {
    tableData.each(function() {
      if ($(this).find('input').prop('type') == 'select') {
        arrayOfThisRow.push($(this).find('input').val());
      } else {
        arrayOfThisRow.push($(this).text());
      }
    });
    myTableArray.push(arrayOfThisRow);
  }
});
Sign up to request clarification or add additional context in comments.

Comments

0

You have to keep the id of the dropdown stored in array and store the dropdown options separately in an array with index. if you just wantto store content of each td then best is to serialise it and store it and then deserialise and restore it when needed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.