I have dynamically generated table ,
<c:forEach var="user" items="${usermap}">
<tr>
<td>${user.getUserName()}</td>
<td>${user.getIsActive()}</td>
<td class="status">${user.getBadLoginAttempts()}</td>
<c:choose>
<c:when test="${user.getBadLoginAttempts()=='Active'}">
<td><a href="#" class="btn btn-sm btn-primary unlockBtn" id="togBtn_${user.getUserName()}" >Lock</a></td>
</c:when>
<c:otherwise>
<td><a href="#" class="btn btn-sm btn-primary unlockBtn" id="togBtn_${user.getUserName()}" >UnLock</a></td>
</c:otherwise>
</c:choose>
</tr>
</c:forEach>
I am doing some db operation on click of link its working fine. So script is,
$(document).ready(function(){
$(document).on('click','.unlockBtn',(function (e) {
//get the user id
var $this = $(this);
var userStatus=$(this).closest('tr').find('td:eq(2)').text();
if(userStatus=='Active'){
alert("Active in if");
alert(userStatus);
$.post('<%=request.getContextPath()%>/controller/UserLockController',{'userName':$(this).closest('tr').find('td:eq(0)').text()},
function(data)
{
$this.closest('tr').find('.status').html(data);
$this.closest('tr').find('td:eq(3)').replaceWith("<td><a href='#' class='btn btn-sm btn-primary unlockBtn' >Unlock</a></td>");
});
}
else{
alert(userStatus);
$.post('<%=request.getContextPath()%>/controller/UserUnlockController',{'userName':$(this).closest('tr').find('td:eq(0)').text()},
function(data)
{
$this.closest('tr').find('.status').html(data);
$this.closest('tr').find('td:eq(3)').replaceWith("<td><a href='#' class='btn btn-sm btn-primary unlockBtn' >Lock</a></td>");
});
}
}));
});
So every functionality is fine . The problem I m facing is for every row I am able to lock or unlock only once. I want it all the time how to achieve it . please help me.