I have an issue to get the multiselect dropdown selected based on the data. This is update action. When I go to update the roles I need this multislect to have previously checked box to be checked once I enter the page. I am doing in the below method as code pasted.
jquery Code
$(".checkbox-val").hide();
var count = 1;
if(count == 1){
$(".checkbox-val").hide();
var a = "["+$(".checkbox-val").text()+"]";
var arr = a.split(",");
console.log(a);
$("#lstFruit").val(a);
alert(a);
$("#lstFruit").multiselect({
includeSelectAllOption: false,
numberDisplayed: 0,
enableFiltering: true,
});
$("#lstFruit").multiselect("refresh");
}
and my div code from where I am retrieving the text
for ($i=0; $i < $count; $i++){ ?>
<div class="checkbox-val" style="font-size: 0px;"><?php echo '"'.$user1[$i].'"'.',';?> </div>
<?php } ?>
- When I alert or log "var a" I get this output ["Risk Assessor", "Risk Manager",].
-
When I put the same content in
$("#lstFruit").val(["Risk Assessor", "Risk Manager",]);
-
With above code I get selected checkbox as expected.
-
Instead of the above code I use variable a in place of the array above.
$("#lstFruit").val(a);
What can I do to achieve what I want. Is there any alternative for this?
Aucun commentaire:
Enregistrer un commentaire