Ccheckbox Column Values Through Javascript/jquery

<?php

$form=$this->beginWidget(‘CActiveForm’, array(

				'id'=&gt;'ConsultationNew',            


				'enableAjaxValidation'=&gt;false,


				'enableClientValidation'=&gt;true,


				


			  ));     

?>

echo CHtml::submitButton(‘PrintSites’, array(‘name’ => ‘PrintSites’,‘onclick’=>‘return Sendchk()’));

    &#036;this-&gt;widget('zii.widgets.grid.CGridView', array(


'id'=&gt;'consultation-new',


'dataProvider'=&gt;&#036;model-&gt;search(),


    'summaryText' =&gt; 'Displaying {start} - {end} of {count} result(s).',





'filter'=&gt;&#036;model,


   


'columns'=&gt;





        array(


           array(      


                        'class'=&gt;'CCheckBoxColumn',


                        'id'=&gt;'chk',


                        'selectableRows'=&gt;'50',


                        //'htmlOptions'=&gt;array('width'=&gt;'40px'),


                                  


            ),

<?php $this->endWidget(); ?>

<script>

function Sendchk()

{

   &#036;('#ConsultationNew').attr('action',&quot;index.php?r=ConsultationNew/printsites&quot;);


     &#036;('#ConsultationNew').submit();

}

</script>

I want to check whether any checkboxes are selected or not when some one clicks the print button without selecting any check boxes and I want to give an alert message when it is clicked. Is there any way to do it with ccheckboxcolumn?

I wrote javascript function for checkbox to select minimum one box.




function Checkbox_Selection_Value_From_Group (){

   selectids= $(\"input[name='yourgroupname[]']:checked\").map(function() { 

            return this.value; 

          }).get();

    if(selectids==''){

        alert('Select Minimum One Check Box');

        return false;

    }else{

	// You Will get comma separated value		

        // 1,2

         $('#ConsultationNew').attr('action',"index.php?

                            r=ConsultationNew/printsites");

          $('#ConsultationNew').submit();

    }

}



In yii, using your function




Yii::app()->clientScript->registerScript('printjs', "

function Sendchk(){

   var selectids= $(\"input[name='yourgroupname[]']:checked\").map(function() { 

            return this.value; 

          }).get();


    if(selectids==''){

        alert('Select Minimum One Check Box');

        return false;

    }else{

	// You Will get comma separated value	1,2


         $('#ConsultationNew').attr('action',"index.php?

                            r=ConsultationNew/printsites");

          $('#ConsultationNew').submit();

    }

}


");



Thanks bala, what’s the ‘yourgroupname[]’ mentioned in the input tag, name of the ccheckbox column? and I am new to Yii, where to use the Yii::app()->clientScript->registerScript function?

see this link http://www.bsourcecode.com/2012/11/yii-ajax.html and see the code on header

"Sample code for ajaxButton 2:"