Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
¿Cuál es el significado de onsubmit="return false" ? ¿Por qué onsubmit="false" no funciona? ¿Cuál es la diferencia entre ellos?

La función formValidation () devuelve falso pero no impide el envío del formulario

 <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>

Cuando he usado la función de retorno al frente de la función formValidation (), está funcionando

 <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 answers
Answer question

0

Los controladores en línea como estos se convierten esencialmente en un cuerpo de función. Dicha función se ejecuta cuando se dispara el evento.

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

Si la función devuelve falso, se evita la acción predeterminada del evento (como enviar el formulario).

 <form onsubmit="formValidation()"

no funciona porque la función construida que se ejecuta no devuelve nada:

 function theHandler() { formValidation() }

Pero

 <form onsubmit="return formValidation()"

funciona porque entonces la función construida es como

 function theHandler() { return formValidation() }

Es algo confuso, y es una de las (muchas) razones por las que nunca debe usar controladores en línea. Adjunte el detector de eventos correctamente usando JavaScript en su lugar.

 document.querySelector('form').addEventListener('submit', formValidation);
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!