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

293
Views
SPA: ¿Cómo envío un formulario en un evento onChange sin el botón de envío?

¿Cómo envío un formulario en un evento onChange de una etiqueta en un SPA, sin activar el comportamiento predeterminado (recarga de página)? Descubrí que puedo acceder al formulario desde el evento con el elemento .form . Pero si .form.submit() , la página se vuelve a cargar aunque lo haya indicado on:submit|preventDefault .

Preparé un ejemplo de mi Problema: https://svelte.dev/repl/894212c7c3d847dd961745f5e9d5750a?version=3.46.2

¿También hay una forma limpia/correcta/de mejores prácticas de resolver esto, sin usar un botón de envío?

¡Gracias de antemano por tu ayuda!

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

0

Tome los datos del formulario con el constructor FormData . Luego PUBLIQUE con Fetch ,XMLHttpRequest o cualquier herramienta HTTP que prefiera.

 const myForm = document.getElementById('myForm'); const formData = new FormData(myForm); const XHR = new XMLHttpRequest(), XHR.addEventListener( 'load', function( event ) { alert('DONE!'); } ); XHR.send( formData );

La forma limpia es usar una biblioteca de formularios para javascript O formularios html simples. ¿Qué tiene de malo volver a cargar la página cuando hacen clic en enviar?

about 4 years ago · Juan Pablo Isaza Report

0

Envíe un formulario con onChange. No se recomienda enviar un formulario desde onChange.

 <script type="text/javascript"t> function submit(event): document.getElementById('meow').submit() event.preventDefault() // put it at the end to prevent page reload <script/> <form id="meow"> <input onChange="submit()" type="text" name="n" placeholder="enter your name"/><br/> </form>
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!