-2
Whenever I put the required property, my scrip stops working.
How can I insert a required
input without the tag form
?
var cont1 = 1;
var cont2 = 2;
var cont3 = 3;
document.getElementById("btnSubmit").onclick = function() {
var radios = document.getElementsByName("nome-radio");
for (var i = 0; i < radios.length; i++) {
if (radios[i].checked) {
console.log("Escolheu: " + radios[i].value);
if (radios[i].value == cont1) {
console.log("ola 1");
} else if (radios[i].value == cont2) {
console.log("ola 2");
} else if (radios[i].value == cont3) {
console.log("ola 3");
}
}
}
}
<html lang="pt-br">
<head>
<title>Exemplo</title>
<meta charset="utf-8">
</head>
<body>
<form>
<p>
<input type="radio" name="nome-radio" value=1>Teste 1
<input type="radio" name="nome-radio" value=2>Teste 2
<input type="radio" name="nome-radio" value=3>Teste 3
</p>
<p>
<input type="button" id="btnSubmit" value="Entrar" />
</p>
</form>
</body>
</html>
What do you want to do?
– Augusto Vasques