I have a form where I have to validate the name, the schedule if it is morning or afternoon and accept the registration rules.
With what I have problems, it is the subject of the schedule, I have two radio buttons but I can not validate that one of the two is selected.
function validar(){
valor = document.getElementById('nombre').value;
if( valor == null || valor.length == 0) {
alert('Error, rellena el campo nombre');
return false;
}
if(!registro.checked ){
alert('Debe aceptar el registro');
return false;
}
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script src="script.js"></script>
</head>
<body>
<form id="formulario" onsubmit="validar()">
<label>Nombre: </label><br>
<input type="text" id="nombre" name="nombre">
<br><br>
<label>Horario:</label><br>
<input type="radio" id="horario" value="mañana"><label>Mañana</label>
<br>
<input type="radio" id="horario" value="tarde"><label>Tarde</label>
<br><br>
<label>Aceptar las normas de registro:</label><br>
<input type="checkbox" name="registro" value="registro" id="registro">
<br><br>
<input type="submit" value="Enviar">
</form>
</body>
</html>