Verify buttton radio

0

The code below only confers the first input radio, does anyone know how to fix it so that it recognizes at least one radio input marked

$(document).ready(function(){
$(document).on('click','#teste',function(){
      if($('#area').is(":checked"))
			{
        alert('marcado');
			}
			else
			{
        alert('n marcado');
      }
      });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputtype="radio" name="area" id="area" value="vl1">

<input type="radio" name="area" id="area" value="vl2">

<input type="radio" name="area" id="area" value="vl3">

<input type="radio" name="area" id="area" value="vl4">

<button id="teste">TESTE</button>
    
asked by anonymous 26.07.2017 / 19:12

2 answers

3

To capture radio "checked" :

$(document).on('click','#teste',function(){
     checkRadio();
});

function checkRadio() {
    var isChecked = $("input[name=area]:checked").val();
    if (!isChecked) {
        alert('Selecione algum logotipo');
        return false;
    }
}
    
26.07.2017 / 19:15
0

$('#teste').click(function(){
  var valor = $('input[name=area]:checked').val();
  if (valor != null){
    alert ("Opção selecionada: "+valor);
  }
  else {
    alert ("Selecione uma opção!");
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><inputtype="radio" name="area" value="vl1">

<input type="radio" name="area" value="vl2">

<input type="radio" name="area" value="vl3">

<input type="radio" name="area" value="vl4">

<button id="teste">TESTE</button>
    
26.07.2017 / 19:22