var ciContact = data.split(", ");
var tmpHash = {};
for(var i = 0; i < ciContact.length; i++){
tmpHash[$.trim(ciContact[i])] = 1;
}
$('input[name="ciContact[]"]').each(function(){
if($(this).val() in tmpHash){
$(this).attr('checked', 'true');
}
}
or there is a new javascript library called tog, you can use it to handle ajax.
function checkBox(data, all_options){
var ciContact = data.split(", ");
var tmpHash = {};
for(var i = 0; i < ciContact.length; i++){
tmpHash[$.trim(ciContact[i])] = 1;
}
return Tog().map(all_options, function(opt, key, _num){
var t = tog.Td().Tog('label').checkbox('$ciContact[]')
.id('ciContact_', _num);
if(opt in tmpHash){ t.checked() }
t.close().cont(opt);
return t;
}).html();
}
Calling checkBox (data, parameters) will give you a html fragment. and you can add it to something like $ ('table tr') On your backend, you just need to dump all your parameters into a json string. And your client side can easily get this as this so-called "all_options"
source
share