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

160
Views
Detener la actualización después de hacer clic en enviar formulario

¡Estaba tratando de completar todo el formulario antes de actualizar! Quiero decir, si el nombre es incorrecto, no quiero que la página se actualice presionando enviar, ¡quiero que espere hasta que complete todas las entradas y todo salga bien!

Intenté devolver falso después de cada instrucción if pero no funciona. ¡Intenté e.preventDefault ninguno funciona! Alguna ayuda ?

 function validateForm(){ var name = document.loginForm.name.value var email = document.loginForm.email.value var password = document.loginForm.password.value var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/; if (name.length == 0) return alert("Name wrong"); else if (re.test(email) == false) return alert('Enter a valid email'); else if (password.length < 6) return alert('password should be more than 6 characters'); else return alert('Form submitted') }
 <div> <form action="" name="loginForm" onsubmit=validateForm()> <label for="">name</label> <input name="name" type="text"> <label for="">email</label> <input name="email" type="email"> <label for="">password</label> <input name="password" type="password"> <button type="submit">Submit</button> <button type="reset">reset</button> </form> </div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe evitar el comportamiento predeterminado de enviar un formulario utilizando el objeto de evento. Dentro de su función validateForm() :

 function validateForm(e){ e.preventDefault(); ... }

Asegúrese de tomar el objeto de evento como un parámetro dentro de la función. Esto evitará que la página se actualice cada vez que se envíe el formulario.

about 4 years ago · Juan Pablo Isaza 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!