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

239
Vistas
How to capture boolean value from swal() function and return it to a validation function that prevents or allows form submission?

I have the following code structure. I want to be able to capture the true/false value from swal function and return it to validate_empty_fields(). I know the following code only returns a promise object and swal only allows you to nest the true/false code within a then function. Is there a way to return the respective value when a user clicks the cancel or ok button.

function validate_empty_fields()
        {
            
            let x = document.forms["myform"]["title"].value;
            let y = document.forms["myform"]["description"].value;
            let z = document.forms["myform"]["image"].value;
            if(x=="" && y=="" && z== "")
            {
                swal('warning','Atleast one of the fields must be filled');
                return false;
            }
            else if(x=="" || y== "" || z== "" )
            {
                
                return swal({title: 'warning',
                      text: 'Empty fields will be pushed as such',
                      buttons:true}); 
    
            }
    
        }
    </script>
    
    <form action="addpages.php" name="myform" method="POST" onsubmit="return validate_empty_fields()" enctype="multipart/form-data">
        //input fields for title,description and image
      <button id="submit-btn" type="submit" >ADD PAGE</button>   
    </form>
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