Reputation: 541
I have a small question: I want to get a one table value row by row my selected cell value. I use for loop for select each row.For loop is correct but I cannot see anything in alert.
My table is
<div style="overflow-x:auto;">
<table id="abctable" class="display nowrap" cellspacing="0" border="0">
<thead>
<th width="15%">Registered Agents</th>
</thead>
<c:forEach items="${Agentsdetail}" var="Agent">
<tr>
<td><input type="text" id="a" value="${Agent.vatNumber}"></td>
</tr>
</c:forEach>
</table>
</div>
I want to select this table cell value of each row to alert. I use this jQuery code:
<script>
$(document).ready(function () {
var table = document.getElementById("abctable");
var rowCount = table.rows.length;
for (i = 1; i <= rowCount; i++) {
alert($('#userstable tr:eq(1) td:eq(0)').val());
}
});
</script>
The row count is successful and when run a program, it returns nothing in the alert. Please help me
Upvotes: 0
Views: 76
Reputation: 1149
As MartinWebb said, the table id is "usertable" not "abctable"
But also the value you are looking for is on the input, not the table cell (td), so your selector is incomplete.
$(document).ready(function() {
var table = document.getElementById("userstable");
var rowCount = table.rows.length;
for (i = 1; i <= rowCount; i++) {
alert($('#userstable tr:eq(1) td:eq(0) input').val());
}
});
Upvotes: 1