Ricardo M.O.
Ricardo M.O.

Reputation: 31

Why the validation function doesn't execute

I trying to validate a form with jquery, but the function "validacion()" doesn't work.

I'm doing it on apache and eclipse.

Form

<form action="destino.html" method="post" id="formularioDarAlta" onsubmit="return validacion();">
<fieldset>
<legend>Formulario alta libro</legend>
...
    <p>
        <input type="submit" value="Insertar"/>         
    </p>
</fieldset>
</form>

Script

<script>
function validacion() 
{   
    var isbn = $('#isbn').val();
    var titulo = $('#titulo').val();
    var categoria = $('#categoria').val();
    var respuesta = true;

    if(isbn.value == "")
    {
        alert("Debe ingresar ISBN");
        respuesta = false;
    }       
    if(titulo.value == "")
    {
        alert("Debe ingresar título");
        respuesta = false;
    }           
    if(categoria.value == "")
    {
        alert("Debe ingresar categoría");
        respuesta = false;
    }       
    return respuesta;           
}
</script>

Upvotes: 0

Views: 53

Answers (1)

meteor
meteor

Reputation: 2568

You need not use isbn.value since you already do $('#isbn').val() Here is a fiddle with updated code http://jsfiddle.net/674hv53e/1/

 if(isbn == "")
    {
        alert("Debe ingresar ISBN");
        respuesta = false;
    }   

Upvotes: 2

Related Questions