samedi 14 mars 2020

Checkbox checked based on Databased value

I have a dynamic checkbox. All the checkbox has dynamic ID as shown in code below. This checkbox is bind using "TABLE1".

<input type="checkbox" class="level-one" id="22" name="chkRoles" value="RecordOne">
<input type="checkbox" class="level-one" id="22" name="chkRoles" value="Recordtwo">
<input type="checkbox" class="level-one" id="19" name="chkRoles" value="Recordthree">
<input type="checkbox" class="level-one" id="30" name="chkRoles" value="RecordFour">
<input type="checkbox" class="level-one" id="35" name="chkRoles" value="RecordFive">
<input type="checkbox" class="level-one" id="25" name="chkRoles" value="RecordSix">

I am fetching the data from other TABLE, let's say TABLE2. Which contain value19,22,25.

var sectionLevelOne = "19,22,25";
var levelArrayOne = sectionLevelOne.split(",");
$.each(levelArrayOne, function (index, value){
       $("chkRoles_"+id).prop("checked",true);
});

I want to checked those CHECKBOX whose ID is "19,22,25".




Aucun commentaire:

Enregistrer un commentaire