how to retrieve multiple checkbox value

i have been using multiple checkbox in a page…if and i created all the checkbox in the same name like

<?php

$i=0;

echo CHtml::activeCheckBox($form,'select',array('name'=>'sel['.$i.']','va'=>$vaca->vacationtype));?>

$i=$i+1; ?>how do i retrieve value from it when multiple checkbox have been checked…

$form->select should give you the selected values.

no i cant get the values when i use $form->select…plz do help me someone

I think what you need is CHtml::activeCheckBoxList() which will generate the list of checkboxes for you.

no i am using pagination for displaying ten records per page and each record has to be given a check box and so i created in the above decribed way…tell me the way to create and retrieve value when the checkbox gets clicked in a better way …someone do help me

You want to take the values at the post script?

I Have done someting simiral with plain php ant input text

<input type='text' name='ip[0]'>


<input type='text' name='ip[1]'>

At the post the

$_post[‘ip’]
is an array of the values.

At javascript maybe a loop at boxes and see if they are selected ?

k i agree with see above i can able to identify which checkbox has been clicked but i was not able to retrieve the "va" which i have used…

CHtml::activeCheckBox($form,'select',array('name'=>'sel['.$i.']','va'=>$vaca->vacationtype))

someone help me

So you want to take the value with  javascript?

I wrote this

echo CHtml::activeCheckBox($model,'id',array('name'=>'sel[0]',


'va'=>'1','onclick'=>'doing(this.id)'))

As Yii supports Jquery

<script>function doing(id)


    {alert($("#"+id+"").attr('va'))}


</script>

There is a message at netbeans that attr(‘va’) is not supported at IE 5.5  ???, why you do not set the ‘value’ ?

alert($("#"+id+"").val()

i forget to mention athing …i.e checkbox should be checked …any no of check box can be checked and when i click a submit button i need the values of the checkboxes…it will be better if u suggest me a way for retrieving multiple values form the check box…do help me plz

All this with javascript?

So you may see http://stackoverflow…ments-in-jquery

i cant get u could u plz explain me further

Please refer to http://www.yiiframew…uide/form.table

i used the method that u have notified but its not working

Vikramsundar88

If you need to "remember" a list of checkboxes which are ticked across a collection of pages in a paginated list without using form posts then the following works for me.

It uses the prototypejs library but no doubt it could be modified to use jquery. it works by using cookies to remember which checkboxes are ticked on each page.

download the attached cookies.js file and install a recent version of prototype http://www.prototypejs.org/

To include relevant js scripts in the page use following



<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/prototype.js" type="text/javascript"></script>


<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/cookies.js" type="text/javascript"></script>


Assuming you have a page containing a paginated list add a checkbox to the table with the name 'rememberMe'. Here I want to remember the id of the model entity which is checked so I assign the id of the model as the checkbox id



<?php foreach($xxxList as $n=>$model): ?>


        ......


       <input class='rememberMe' id='<?php echo $model->id; ?>' type='checkbox'  />


       .......


<?php endforeach; ?>


To retrieve the list of checked ids or reset (uncheck) the list I use the following form element at the bottom of the page containing a hidden field which will contain the list of ids submitted by the form. The exportIDs() function (contained in cookies.js) assigns the ids of the checked boxes to the hidden field.



<form method='post' action='xxx' name='xxx'>


  <input id='ids' name='ids' type='hidden' />


  <input type="submit" value="List" onclick="$('ids').value = exportIDs();"/>


  <input type="reset" value="Clear" onclick="eraseAllCookies(); reloadPage();"/>


</form>


Then in the controller action handling this post you can extract the list of ids submitted in the post into an array as follows



 $ids = explode(',', $_POST['ids']);


Hope this makes sense. If anyone has a better solution could they let me know.

Returning to the original question

I suggest http://www.yiiframework.com/doc/cookbook/81/