i dont even know how to write the question , but i have a list of check boxes and i can insert their data as a json to my database using php . what i want now is when i open the page without refreshing, grab the json and check boxes that needs to be checked and leave the others empty .
i'm aware that ajax can pull this off but i have no ajax skills what so ever
My HTML
<div style='display:none;' id="priv">
<li><input name="chk[]" id="settings" value="settings" type="checkbox">Can Access Settings</input></li>
<li><input name="chk[]" id="view_team" value="view_team" type="checkbox">Can View Team Data</input> </li>
<li><input name="chk[]" id="delete_team" value="delete_team" type="checkbox">Can Delete Team Profile</input></li>
<li><input name="chk[]" id="edit_team" value="edit_team" type="checkbox">Can Edit Team Profile</input> </li>
the is a select menu before these check boxes that contains a few items , so whenever i choose an item , it should send a request to my database , get the checked values and fill those checkboxes accordingly
<select onchange="showDiv('priv', this)" id="role_selector" name="roles">
<option value='0' disabled selected >Please Choose</option><
<option value='0' disabled selected >Admin</option>
<option value='0' disabled selected >Editor</option>
i have a javascript function to show and hide the div that contains the check boxes
function showDiv(divId, element){
document.getElementById(divId).style.display = element.value == 1 ? 'block' :'none';
}
my PHP code
if (isset($_POST['chk'])) {
$access=$_POST['chk'];
}
$json=json_encode($access);
$sql= "UPDATE `roles` SET privilege='$json' WHERE `id`=$role_id ;";