I have a modal that looks like this:
After few checkboxes has been checked and after clicking on Add Users to New Group modal closes and I'm catching values of checked checkboxes. But now I need those checkboxes that were checked before closing modal to stay checked after opening modal again, so that user can see which one of checkboxes he checked, if that is even possible to do. Here is what I tried:
$(document).ready(function(){
$('#addNewMembers').click(function(){//click on Add Users to New Group button
var selected = $('#ovdjeSuSelektovani').val();//im putting value of all checked checkboxes inside hidden input, so this is how i'm retrieving those values
console.log(selected);
if(selected!='') {
var arrayOfSelected = selected.split(",");
for(var i=0;i<arrayOfSelected.length;i++){
$('checkbox value=['+arrayOfSelected[i]+']').prop('checked',true);//did not recognize the jQuery selector
}
var numberOfSelected=arrayOfSelected.length;
$('#numberOfMembers').text(numberOfSelected)
}else{//neko upozorenje
}
});
Did not work. Attempt No.2:
$("#modal-6 input[type='checkbox']:checked").each(function () {
this.prop('checked',true);
});
Did nothing after reopening the modal. If anyone has any advice, I would be glad to try it.
Aucun commentaire:
Enregistrer un commentaire