I'm trying to get the value of input radio
, but if I do:
document.querySelector('input[name="group1"]:checked').value;
It returns me " ON ". Does anyone know what can it be? I was expecting it to return me Red
, Yellow
or Green
.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="modal6" class="modal">
<div class="modal-content">
<h4>Escolha uma categória</h4>
<form action="#" id="form">
<p>
<input class="with-gap" name="group1" type="radio" id="test1" />
<label for="test1">Red</label>
</p>
<p>
<input class="with-gap" name="group1" type="radio" id="test2" />
<label for="test2">Yellow</label>
</p>
<p>
<input class="with-gap" name="group1" type="radio" id="test3" />
<label for="test3">Green</label>
</p>
</form>
<a class="waves-effect waves-light btn btn-confirmar" style="width: 80%; margin: 25px 10% 25px 10%;">confirmar</a>
</div>
</div>
<script type="text/javascript">
$(".btn-confirmar").click(function(){
var teste = $('input[name="group1"]:checked').val();
alert(teste);
});
</script>