I have the following JS code to validate a form and the execution does not reach the validate function.
window.onload = inicializar;
function inicializar() {
var formulario = document.getElementById("formulario");
if (formulario) {
formulario.addEventListener('submit', validacion);
} }
function validacion() {
var form = event.target;
if (form.fecha.value == "") {
event.preventDefault();
document.getElementById('mssFecha').style.display = "block";
} else if (form.nombre.value == "") {
event.preventDefault();
document.getElementById('mssNombre').style.display = 'block';
} }
}
Any suggestions?