Trouble getting value attribute of input element
I have a table with several columns containing input elements populated from a database, e.g.,
<input class="calc" type="text" value="5" /> //value populated by PHP
On every row, I need to perform a calculation using the value of several input fields. So I tried to access the value of the first input field like so (which had worked in another function):
var row = $(this).closest("tr");
($(row).find('input:eq(0)').val();
But for some reason it's returning a 0, and the line below also doesn't work:
($(row).find('input:eq(0)').attr('value');
But this returns the correct class, so I know it's finding the element:
($(row).find('input:eq(0)').attr('class');
And if I assign the input element an id, say "count," this works:
$('#count').val();
Obviously I don't want to fuss with individual id's to get the values. Can someone help me understand why the first two examples don't work, and how to fix them?
Thanks!
Kathryn