jquery - yii2 kartik switch input type radio button get value in javascript -


i use yii2 kartik switch input type radio , want value of selected option in javascript (specially in jsexpression), here code :

        $model->orientation = 'portrait';         echo $form->field($model, 'orientation')->widget(switchinput::classname(), [             'name' => 'information_orientation',             'type' => switchinput::radio,             'value' => 'portrait',             'items' => [                 ['label' => 'portrait&nbsp&nbsp&nbsp', 'value' => 'portrait'],                 ['label' => 'paysage&nbsp&nbsp&nbsp', 'value' => 'paysage'],             ],             'pluginoptions' => [                 'ontext' => 'oui',                 'offtext' => 'non',                 'oncolor' => 'success',                 'offcolor' => 'danger',                 'size' => 'mini'             ],             'labeloptions' => ['style' => 'font-size: 13px'],         ]); 

i have tried :

$([name='information-orientation']).val() 

but returned undifined value

switchinput class does not care name property give it
according docs, need wrap name in options array

echo $form->field($model, 'orientation')     ->widget(switchinput::classname(), [         'options' => ['name' => 'information_orientation'],         'type' => switchinput::radio,  .... 

from docs:

options: array html attributes widget input tag.

edit:
can use following

// value: $("[name='information_orientation']").val()  // check if switch or on off $("[name='information_orientation']").prop('checked') 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -