I do not validate a form.

0

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?

    
asked by Alexander 23.06.2018 в 02:05
source

0 answers