0
I’m trying to get the value of input radio
, but if I do:
document.querySelector('input[name="group1"]:checked').value;
He returns to me "ON". Does anyone know what it might be? I was hoping he’d get back to me Red
, Yellow
or Green
.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="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>
And my dear, blz? So the problem is that you are recovering the value of
input
and not ofLabel
where is your Red, Yellow... The tip is this, anything gives a touch that I try to pass you a code running this.– Rafael