I am trying to display the checkboxes values like if the DB contains the following
Array
(
[0] => Array
(
[userid] => 868
[username] => Pavanasri
[firstname] => Pavana
[email] => [email protected]
[signupdate] => 2020-07-13
[add_topic_priv] => Y
[add_subject_priv] => Y
[add_post_priv] => Y
[add_note_priv] => Y
[add_disable_priv] => N
[add_notifications_priv] => Y
)
[1] => Array
(
[userid] => 785
[username] => sam123
[firstname] => sam
[email] => [email protected]
[signupdate] => 2020-07-23
[add_topic_priv] => Y
[add_subject_priv] => Y
[add_post_priv] => Y
[add_note_priv] => Y
[add_disable_priv] => N
[add_notifications_priv] => Y
)
)
So here I have some fields fetching from the DB and first 5 fields are displaying in the table . But coming to the checkbox values how can I display the checked values [y] on the front end using jquery. Here is the jquery code.
window.fillData = function(){
alert("memberslist");
var gid = $("#proid").val();
$.ajax({
type:"POST",
dataType:"json",
url:"memberslist.php",
data:{
gid:gid,
action:"membersList",
},
success : function(response)
{
if(response.status=="1")
{
response.data.forEach(function(item) {
if (item.add_topic_priv =="Y")
{
$("#topic").is(":checked");
}
var row = "<tr>";
row += "<td id=tid>" + item.username + "</td>";
row += "<td id=firstname>" +item.firstname+ "</td>";
row += "<td id=email>" + item.email + "</td>";
row += "<td id=signupdate>" + item.signupdate + "</td>";
row += "<td id=invitedon>" + item.invitedon + "</td>";
row += "<td id=acceptedon>" + item.acceptedon + "</td>";
row += "<td> <input type=checkbox id=topic name=example2 class=td-check-box> </td>";
row += "<td> <input type=checkbox id=subject name=example2 class=td-check-box> </td>";
row += "<td> <input type=checkbox id=post name=example2 class=td-check-box> </td>";
row += "<td> <input type=checkbox id=note name=example2 class=td-check-box> </td>";
row += "<td> <input type=checkbox id=disable name=example2 class=td-check-box> </td>";
row += "<td> <input type=checkbox id=notification name=example2 class=td-check-box> </td>";
row += "<td><i id=deletep class=\'fa fa-trash-o\'></i></td>";
row += "</tr>";
$("#tableid").append(row);
})
}
},
error : function(response){
$("#succ_msg").html("<p style=\'color:red;font-weight:bolder;\'>error</p>");
}
});
return false;
}
In the above code i am trying to print the fields but coming to the checkboxes it is not display checked for the id of "topic" . How can we fetch checked value to the html through jQuery. So I can Apply to other fields.
