0

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.

IfTrue
  • 489
  • 8
  • 25
LuisRox
  • 57
  • 1
  • 1
  • 8
  • 1
    could you provide html generated by php ? – Ashot Sep 01 '15 at 20:00
  • Your radio buttons don't have `id` values. `#modificaciones-aumento` is the `id` of your `div` -> `
    `. Try `#modificaciones-aumento:radio` -> `$('#modificaciones-aumento:radio').change(function(){` (this was based off the html code in your comment that was deleted)
    – Sean Sep 01 '15 at 20:06
  • – LuisRox Sep 01 '15 at 20:07
  • You need to select all radio inputs, like $("input:radio[name=theme]").click(function() { var value = $(this).val(); }); http://stackoverflow.com/questions/986120/in-jquery-how-do-i-select-an-element-by-its-name-attribute – Aston Sep 01 '15 at 20:08
  • not working Sean nor Aston :C – LuisRox Sep 01 '15 at 20:11

1 Answers1

1

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/

Sean
  • 12,443
  • 3
  • 29
  • 47