I have a table that has multiple rows. I am trying to return the row # that contains an input which has a value in it. I understand what I’m doing wrong… my selector is only selecting 1 row, instead of the row # I’m in. http://jsfiddle.net/silvajeff/4Sb8K/
<table id="oustandingItems">
<tr><th>Category</th></tr>
<tr><td><input name="mytest" /></td></tr>
<tr><td><input name="mytest" value="123"/></td></tr>
<tr><td><input name="mytest" /></td></tr>
<tr><td><input name="mytest" /></td></tr>
</table>
<button id="findRow">Find Row</button>
<input type="text" id="myRow" />
$("#findRow").click(function() {
var tableRow = $('#oustandingItems tr:has(td input[value!=""])').prevAll().length;
$("#myRow").val(tableRow);
});
This ended up being the correct solution, only I was using an incorrect jquery version. This solution works with jquery 1.7.2 and up which is what I tested with.
http://jsfiddle.net/silvajeff/4Sb8K/