Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
Form object in the console gets deleted on submit

This is my form and I am trying to output the submitted details as an object. The doubt I have is how can I prevent the form from submitting when fields are empty? I want to check whether all the functions above validate() is true or not and then execute the validate function if not true, prevent the form from submitting. The errors that are shown stays there in the form even after submission. I have tried to refresh the window using window.location.reload() but then the object I want is lost by this method. Is there any way I can achieve this?


x = "correct"


function nameValidate(value) {
    namev = value;
    if (namev.length <= 3) {
        
        var nameError = "Enter a valid name"
        document.getElementById("nameerror").innerHTML = nameError
        //return 1;
    } else {
        document.getElementById("nameerror").innerHTML = x
        //return 0;
    }

}

function emailValidate(value) {
    emailv = value;
    if (emailv.length < 5) {
        var emailError = "Enter a valid email"
        document.getElementById("emailerror").innerHTML = emailError
        //return 1;
    } else {
        document.getElementById("emailerror").innerHTML = x
        //return 0;
    }

}

function companyValidate(value) {

    if (value === "") {
        var companyError = "Enter a valid company";
        document.getElementById("companyerror").innerHTML = companyError;
        //return 1;
    } else {
        document.getElementById("companyerror").innerHTML = x;
        //return 0;
    }

}

function phoneValidate(value) {
    phonev = value;
    if ( phonev.length !== 10 ) {
        var phoneError = "Enter a valid 10 digit phone number";
        document.getElementById("phoneerror").innerHTML = phoneError;
        //return 1;
    } else {
        document.getElementById("phoneerror").innerHTML = x;
        //return 0;
    }

}

function validate(e) {

    /* Variables for field values and form */
    var name=document.getElementById("name").value;
    var email=document.getElementById("email").value;
    var company=document.getElementById("company").value;
    var phone=document.getElementById("phone").value;
    var desc=document.getElementById("description").value;
    var project=document.getElementById("project").value;
    var form = document.getElementById("form");
    
    //e.preventDefault();   
    console.log({name,email,company,phone,desc,project});
    form.reset();
 }

 //form.addEventListener("submit",validate(),true);
        

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda