jqueryyii2

How to get yii2 clicked radioList value in jQuery?


I have this in my form:

<?= $form->field($model, 'system_user')->inline(true)->radioList(["Yes"=>"Yes","No"=>"No"],['onClick'=>'getValue($(this).val());','id'=>'system_user']) ?>

I need to get the value of clicked radio button in jQuery/javascript, I have implemented this code:

<script>
function getValue($value) {
    alert($value);
}
</script>

But I get an empty alert. Can anyone please assist? I have been stuck for a day now.


Solution

  • You could add an event manager fur input:radio

      $("input:radio[name='your_field_name']:checked").val();
    

    and for yii2

    $("input:radio[name='modelName[fieldName]']:checked").val();