Jump to content

Getting drop-down select value for each row

Recommended Posts


Having some issues with this


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, maybe I'm missing something essential here

$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 () {

// 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 -> 
h2[header] = $td3.eq(i).val();
if ($td3.eq(i).val() === undefined){ // it's not dropdown ? read it normaly.. 
h2[header] = ($td.eq(i).text() == '') ? $td2.eq(i).val() : $td.eq(i).text();


// Output the result

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...