0

how can i get the value of the type=hidden when i click the <tr class='click'>?
i only get the value of first hidden and when i click the other <tr> the same value from first hidden.

jquery code

$(document).ready(function(){

  $('tr[class='click']').click(function(){
     
    var a= $('tr[class='click'] input:hidden').val();
   alert("a");
});

});

html code

<table id='tbform'>
<tr class='click'>
 <td><input type='hidden' id='txtval' value='1' name='txtval[]' ></td>
</tr>
<tr class='click'>
<td><input type='hidden' id='txtval' value='2' name='txtval[]' ></td>
</tr>
<tr class='click'>
<td><input type='hidden' id='txtval' value='3' name='txtval[]' ></td>
</tr>
</table>

Edited by canterorist: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by pritaeas
0

You get the first hidden in your click event, because you repeat the same selector. What you can do is:

$("tr[class='click']").click(function(){
  var a = $(this).find('input:hidden').val();
  alert(a);
});

What it does is start from this (the row you clicked on), and then find the next hidden from there. Note that there is also a problem with your single quotes in the selector.

Edited by pritaeas: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.