Getting drop-down select value for each row

Hello ,

Having some problem reading data from each row from this table.

Given http://codepen.io/caim/pen/pggZOx

I’m trying to replace the first column from input to select dropdown but having trouble figuring out how to read the data for each cell.

It was working fine with an input and normal td but now the select entered the picture and it’s skipping one column.

The day drop-downs are for newly added rows currently.

This is how I’m trying to read the data

$BTN.click(function () {
  var $rows = $TABLE.find('tr:not(:hidden)');
  var $tds = $TABLE.find('td:not(:hidden)');
  var headers = [];
  var data = [];


  // Get the headers (add special header logic here)
  $($rows.shift()).find('th:not(:empty)').each(function () {
    headers.push($(this).text().toLowerCase());
  });

  // Turn all existing rows into a loopable array

  $rows.each(function () {
    var $td = $(this).find('td');
    var $td2 = $td.find('input'); 
    var $td3 = $td.find('select');
    var h2 = {};  
    // Use the headers from earlier to name our hash keys
    headers.forEach(function (header, i) {
    // h2[header] = $td.eq(i).text();  

      //the dropdown value -> 
    //console.log($td3.eq(i).val());
      h2[header] = $td3.eq(i).val();
      if ($td3.eq(i).val() === undefined){ // it's not dropdown ? read it normaly.. 
        console.log(i);        
        h2[header] = ($td.eq(i).text() == '') ? $td2.eq(i).val() : $td.eq(i).text();
      }                 
      //console.log(h2[header]);  

    });   
    data.push(h2);
  });

  // Output the result
  $EXPORT.text(JSON.stringify(data));
});

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.