I wrote a PHP code for prepare jQuery function, which can select multipal values from the html multi select box.
there are different campaigns and it have separate question sets, the one campain has many question sets.
below code returns the output as
$('#q9 select').val('2');
$('#q10 select').val('2');
$('#q10 select').val('1');
but i need this output as
$('#q9 select').val(['2']);
$('#q10 select').val(['2','1']);
to select multipal items, can anyone help please, thank you…
<script>
$(function(){
<?php
foreach ($selectdefaults as $s):
?>
$('#q<?php echo $s['campsetjoin']['campid'];?> select').val('<?php echo $s['campsetjoin']['setid'];?>');
<?php
endforeach;
?>
});
</script>
i agree with the above two answers that either modifying your data structure or using a pure JS solution would be cleaner. however, if neither of them are an option, you could do something like this: