简体   繁体   中英

How to Get A RadioList Value with Javascript Function

I have this:

<?php
$list = [];
$list = [1 => 'Aumento' , 0 => 'Disminución'];

echo $form->field($modi, 'aumento')->radioList($list)->label("<b>Seleccione acción a realizar</b>");

?>

And I need to get the value of the vector "$list" with a function in javascript, I have:

$('#modificaciones-aumento').change(function(){
 var valor = $('#modificaciones-aumento').val();
 alert(valor);
});

But it is not working, I've tried using the function "prop.("checked")" as well, but it did not work either.

Your radio buttons don't have id values. #modificaciones-aumento is the id of your div

<div id="modificaciones-aumento">
    <label>
        <input type="radio" name="Modificaciones[aumento]" value="1"> Aumento
    </label>
    <label>
        <input type="radio" name="Modificaciones[aumento]" value="0"> Disminución
    </label>
</div>

Try #modificaciones-aumento :radio for your selector, and $(this) in your function

$('#modificaciones-aumento :radio').change(function(){
    var valor = $(this).val();
    alert(valor);
});

jsFiddle - http://jsfiddle.net/d6mfuv0c/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM