Html does not render radio button value

-1

I need to get the value of input radius inside a modal bootstrap , but it does not render the value looks like this:

Iusedthisexampleofradios:

<divid="itemList">
<input type="radio" value ="1" class="overWrite" name="overWrite"  />Yes
<input type="radio" value ="2" class="overWrite" name="overWrite"  />No 
</div>

In the debug, I noticed that when I get the value soon to load the page this way:

    $(document).ready(function(){

     var overwrite = $('#itemList input:radio:checked').val();

     alert('value = ' + overwrite);
  });

It can capture the value of the input, however when I get it through the change or click it it returns empty:

    $("input[type='radio']").click(function () {
    var radioValue = $(this).val();
    alert(radioValue);
});

When the modal is loaded on the page the radio input loses its value, in the same form there are other inputs, but this happens only with the radio button. Does anyone know why?

    
asked by anonymous 04.04.2016 / 02:34

1 answer

0

Inputs of type radio are best used for submitting a form, since the name of both must be equal.

To pay the value dynamically, the best way is to use the select tag, it replaces input radio and solves problems.

<!doctype html>
<html>
  <body>
    <select id="option">
      <option value="Yes">Sim</option>
      <option value="No">Não</option>
    </select>
    <input type="button" value="Click" onclick="alert(document.getElementById('option').value);">
  </body>
</html>
    
04.04.2016 / 03:03