I have a table whose cells may contain textboxes, radio buttons, checkboxes I have given each a class - so all textboxes are class "T", checkboxes are class "C" and so on
I want to iterate over all the rows and get the value of each input. I have tried this
function gather() {
var res = '';
var table = document.getElementById("tblQ");
for (var i = 0, row; row = table.rows[i]; i++) {
if (row.style.display !== 'none') {
$('.T').each(function () {
if ($.trim($(this).val()) !== '')
res += $(this).attr('id') + '~' + $(this).val() + '\n';
});
$('.C').each(function () {
if ($(this).is(':checked'))
res += $(this).attr('id') + '~1\n';
});
$('.R').each(function () {
if ($(this).is(':checked'))
res += $(this).attr('id') + '~1\n';
});
}
}
alert(res);
}
<table id="tblQ">
<tr>
<td>
<input id="01" type="text" value="myText" class='T' />
</td>
</tr>
<tr>
<td>
<input id='02' type="checkbox" checked class='C' />
</td>
</tr>
</table>
<p />
<button onClick='gather()'>Test</button>
This gives
01~myTest
02~1
01~myTest
02~1
How do I restrict the ".each" to the class within the current row.