I have a database table that I'm outputting onto a internal webpage. I need to find the value of a selected row so I can then merge the rows and send the value back to the db so it knows which rows to merge.
When clicking on a button to merge rows this is my function I have created:
//merge the rows now
function mergeTheRows() {
//get value from each row
$("#mergeRowsBody tr").each(function() {
rowValue = document.getElementsByTagName("tr").value;
mergeRowsArray.push(rowValue);
console.log(mergeRowsArray);
});
}
Here is the body of the table (I'm only showing two rows for the example):
<tbody id="mergeRowsBody">
<tr class="rowEditData odd mergeSelect" value="110461" role="row">
<td class="mdl-data-table__cell--non-numeric sorting_1">ABBEVILLE</td>
<td class="mdl-data-table__cell--non-numeric">South Carolina</td>
<td class="mdl-data-table__cell--non-numeric">null</td>
<td class="mdl-data-table__cell--non-numeric">null</td>
<td class="mdl-data-table__cell--non-numeric">001</td>
<td class="mdl-data-table__cell--non-numeric">39</td>
</tr>
<tr class="rowEditData even mergeSelect" value="107045" role="row">
<td class="mdl-data-table__cell--non-numeric sorting_1">Abbeville County</td>
<td class="mdl-data-table__cell--non-numeric">South Carolina</td>
<td class="mdl-data-table__cell--non-numeric">001</td>
<td class="mdl-data-table__cell--non-numeric">45</td>
<td class="mdl-data-table__cell--non-numeric">null</td>
<td class="mdl-data-table__cell--non-numeric">null</td>
</tr>
</tbody>
I keep getting undefined when it console logs to the browser. I've tried finding the value by ID and class as well, but it keeps saying undefined. What am I doing wrong?
All I need is to be able to save the ID of the row so I can then let the database know which rows will be merged.