Hi, is it possible to get the values of a checkboxlist on a jQuery? I have the following code
On View:
<?php
$list = [1 => Yii::t('app', 'Leisure'), 2 => Yii::t('app', 'Sport'), 3 => Yii::t('app', 'Technology') , 4 => Yii::t('app', 'Food')];?>
<?=
$form->field($campaign, 'dot_cam_interests')->multiselect($list);?>
<a id="myLink"><?= Yii::t("app","Estimate Dots") ?></a>
$this->registerJs('
$("#myLink").click(function(){
var test= $("input[name='."'Campaign[dot_cam_interests][]'".']:checked");
alert(test.val());
});'
, View::POS_END);
?>
The Html:
<div class="form-group field-campaign-dot_cam_interests">
<label class="control-label" for="campaign-dot_cam_interests">Dot Cam Interests</label>
<div class="bg-white form-control input-multiselect" tabindex="0"><input type="hidden" name="Campaign[dot_cam_interests]" value="">
<div id="campaign-dot_cam_interests">
<div class="checkbox"><label><input type="checkbox" name="Campaign[dot_cam_interests][]" value="1"> Leisure</label></div>
<div class="checkbox"><label><input type="checkbox" name="Campaign[dot_cam_interests][]" value="2"> Sport</label></div>
<div class="checkbox"><label><input type="checkbox" name="Campaign[dot_cam_interests][]" value="3"> Technology</label></div>
<div class="checkbox"><label><input type="checkbox" name="Campaign[dot_cam_interests][]" value="4"> Food</label></div></div></div>
<div class="help-block"></div>
</div>
It only pick up the value from the first checked box.
Is there anyway to get the checked values as one array? Like [1,2,4]?
Thanks