In each row there is a textbox and a button i want to get the textdata to on click of button by their respective textbox. but problam is i am getting the same value for each button click because textboxID is same … in loop
my code is like that …is there any way to get the value of each textbox for diff button click
<% @obj.each_with_index do |time_sheet, i| %>
<tr>
<td style="width:30px;"><input type="text" name="comment" id='commentId'></td>
<td class="table-styling"> <button type="button" id="waiver">Waiver</button></td>
</tr>
<% end %>
$('#waiver').live("click", function() {
var commentVal = $("#commentId").val();
alert(commentVal); //getting same value for each button click
});
of course, ID’s are unique, and it looks like you are mass producing elements with the same ID inside a loop, which is not a good idea, and makes the javascript go boo-boo.