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

230
Vistas
what is the meaning of onsubmit="return false" ? why onsubmit="false" not working? what is the difference between them?

formValidation() function return false but not preventing form submission

<body>
    <script>
        function formValidation(){
            return false;
        }
    </script>
    <form onsubmit="formValidation()" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
        <label for="email">Email:</label><br>
        <input type="email" name="email" id="email"><br><br>
        <input type="submit" name="submit" value="submit">
    </form>
</body>

When i have used return front of formValidation() function it is working

<body>
    <script>
        function formValidation(){
            return false;
        }
    </script>
    <form onsubmit="return formValidation()" method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
        <label for="email">Email:</label><br>
        <input type="email" name="email" id="email"><br><br>
        <input type="submit" name="submit" value="submit">
    </form>
</body>
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Inline handlers like these essentially turn into a function body. Said function is executed when the event is fired.

function theHandler() {
  // Attribute string goes here
}

If the function returns false, the event's default action (such as submitting the form) is prevented.

<form onsubmit="formValidation()"

doesn't work because then the constructed function that gets executed doesn't return anything:

function theHandler() {
  formValidation()
}

But

<form onsubmit="return formValidation()"

works because then the constructed function is like

function theHandler() {
  return formValidation()
}

It's somewhat confusing - and is one of the (many) reasons why you should never use inline handlers. Attach the event listener properly using JavaScript instead.

document.querySelector('form').addEventListener('submit', formValidation);
about 4 years ago · Santiago Trujillo Denunciar
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