Reputation: 113
I have a table with multiple rows with different values - values are inside hidden input - Just like this:
<tr>
<td>UserName 1 <input type="hidden" class="EmployeeID" name="EmployeeID[]" value="1" />
<td><input type="button" class="btn btnDelEmployee" value="Delete" /></td>
</tr>
<tr>
<td>UserName 12 <input type="hidden" class="EmployeeID" name="EmployeeID[]" value="2" />
<td><input type="button" class="btn btnDelEmployee" value="Delete" /></td>
</tr>
I am trying to pass the value of the row once I click the delete input. I tried this code:
$(document).on('click', '.btnDelEmployee', function () {
$.post('', {DelEmployee:1, EmployeeID: $(".EmployeeID").val()}, function(data){
},'json');
});
When I click the second row I get the value of the first row, instead of getting the value of the second row.
Upvotes: 0
Views: 159
Reputation: 60
I recommand you to add an attribute to your field like :
<input type="button" class="btn btnDelEmployee" value="Delete" data-id="2" />
Then :
$(document).on('click', '#btnAddClose', function () {
$.post('', {btnAddClose:1, EmployeeID: $(this).attr('data-id')}, function(data){
},'json');
});
Upvotes: 1