Reputation: 109
I have a dynamic Checkbox and i want to check whether a checkbox is checked or not .When i Check or Uncheck First Checkbox it works Good.If i uncheck remaining checkbox it alerts Checked.Pls help me to overcome this issue.
JQUERY
function CheckRow(ProjectID, BID, LID, PID, ImageID, StatusID) {
if ($("#chkProjectID").prop('checked') == true) {
alert('checked');
Checked(ProjectID, BID, LID, PID, ImageID, StatusID);
} else {
alert('Unchecked');
Unchecked(ProjectID, BID, LID, PID, ImageID, StatusID);
}
}
HTML
<input type="checkbox" id="chkProjectID" onclick="CheckRow(ProjectID=' + full.ProjectID + ',BID=' + full.BID+ ',LID=' + full.LID+ ',PID=' + full.PID+ ',ImageID=' + full.ImageID + ',StatusID=' + full.StatusID + ')" />
Upvotes: 2
Views: 1452
Reputation: 1474
Its happening because your checking for first checkbox only. If you have multiple checkbox created dynamically and want to check if its checked or not then change your code as below :
<input type="checkbox" id="chkProjectID" onclick="CheckRow(this, ProjectID=' + full.ProjectID + ',BID=' + full.BID+ ',LID=' + full.LID+ ',PID=' + full.PID+ ',ImageID=' + full.ImageID + ',StatusID=' + full.StatusID + ')" />
function CheckRow(_this, ProjectID, BID, LID, PID, ImageID, StatusID) {
//it will check for current checkbox
if ($(_this).prop('checked') == true) {
alert('checked');
Checked(ProjectID, BID, LID, PID, ImageID, StatusID);
}
else {
alert('Unchecked');
Unchecked(ProjectID, BID, LID, PID, ImageID, StatusID);
}
}
Upvotes: 2