I want to check or uncheck the checkbox using jquery after getting details from database in edit page using php. I am putting following code at the top of file.
$edit_data = DB::queryFirstRow("select * from items where id='".$_GET[id]."' ");
And html code is:
<div class="form-group col-lg-2" >
<label>Exempted Tax</label>
<label style="cursor:pointer">
<input type="checkbox" name="not_applicable[]" value="1" /> Yes
</label>
</div>
<div class="form-group col-lg-3" >
<label>Status </label><br />
<label style="cursor:pointer">
<input type="checkbox" name="active_status[]" value="1" />
Inactive</label>
</div>
At the end of file, I added the code to check the checkbox based on condition:
echo $edit_data[not_applicable]=="1"?'$(\'input[name="not_applicable"]\').attr("checked", "checked");':'$(\'input[name="not_applicable"][value="'.$edit_data[not_applicable].'"]\').removeAttr("checked");';
echo $edit_data[active_status]=="1"?'$(\'input[name="active_status"]\').attr("checked", "checked");':'$(\'input[name="active_status"][value="'.$edit_data[active_status].'"]\').removeAttr("checked");';
And I also tried prop(). It also gives same output. It doesn't show checkmark if condition is true, after page load.it seems like unchecked if even condition is true. Please help me to resolve this.