zSynopsis zSynopsis - 2 months ago 6
Javascript Question

Jquery Hidden Field in Table

I was wondering if anyone knew of a way to access a hidden field (by client id) within a table row using jquery.

$("#tblOne").find("tr").click(function() {
var worker = $(this).find(":input").val();
});


I find that the above works for a row that has only one input, but I need some help figuring out a way to get the value by the inputs name.

Here's the example of a table row. How would I access the two fields by their id's?

<table id="tblOne">
<tr>
<td>
<asp:HiddenField id="hdnfld_Id" Text='<% Eval("ID") %>'></asp:HiddenField>
</td>
<td>
<asp:HiddenField id="hdnfld_Id2" Text='<% Eval("ID2") %>'></asp:HiddenField>
</td>
</tr>
</table>

Answer

With the way you have it setup right now, you could do this:

$('tr td', '#tblOne').eq(0).find(':input').val(); // find input in 1st TD
$('tr td', '#tblOne').eq(1).find(':input').val(); // find input in 2nd TD

Using this you don't have to worry about the input's ClientID.

Comments