Showing an alert,if checkbox has been pushed

Hi guys,

I try to send a simple alert() using jquery in GridView, but I fail.I only get alertBox pushing first checkbox. Clicking other Checkboxes won’t trigger alertBox.

Any ideas,what is wrong with this code?





   [

                'class' => 'yii\grid\CheckboxColumn','headerOptions'=>['id'=>'cb'], 'checkboxOptions' => function($model) {

                    return ['value' => $model->id];

                },

            ],






.

.


 $search = "$('.search-button').click(function(){

$('.search-form').toggle(1000);

return false;

});";

    $CheckBox = "$('#cb').change(function () {

   		alert();

        }).change();";

    $dummy = 'id';

    $this->registerJs($search);

    $this->registerJs($CheckBox);

.

.



It’s because the identifier must be unique throughout the page. Try this:




<?= GridView::widget([

    'id' => 'blabla',

    'columns' => [

        ['class' => 'yii\grid\CheckboxColumn'],

    ],

]); ?>


<?php

$this->registerJs("

    $(document).on('click', '#blabla input[type=\'checkbox\']', function(){

        alert($(this).val());

    });

");



Ur solution works pretty well. Thx a lot for this…

This thread can be closed as succesfully soveld