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

221
Views
Cómo cambiar la acción del formulario cuando se hace clic en un botón de 'vista previa'

Estoy tratando de obtener una página diferente, preview.php para mostrar cuando se hace clic en el botón de vista previa, cambiando la acción del formulario. El botón de vista previa debería conducir a otra página donde pueda ver las entradas del archivo y tal vez tenga opciones para enviar o volver.

Los otros botones, enviar y borrar funcionan, sin embargo, el botón de vista previa no parece funcionar. Permanece en la misma página incluso después de hacer clic en el botón.

Como prueba puse algunas alertas. Las alertas 'here1' y 'here2' funcionan, pero la alerta 'here3' no funciona, lo que me hace creer que no se alcanza la función changeAct(). ¿Cómo puedo arreglar esto para que la acción del formulario se pueda cambiar?

 const wrapper = document.getElementById('blog-btn'); wrapper.addEventListener('click', (event) => { const btn = event.target.nodeName === 'BUTTON'; if (!btn) { return; } else { processClick(event.target.id) } }); function processClick(id) { alert("Id is "+ id); if(id == "pre") { alert("here 1"); document.getElementById('pre').addEventListener('click', changeAct); alert("here 2"); } } function changeAct() { alert("here 3"); document.getElementById('frm1').action="preview.php"; }
 <form id="frm1" name="post_form" action="addEntry.php" method="post"> <div id="blog-btn"> <!--Post & Clear Form Buttons--> <button type="button" value="Preview" id="pre" >PREVIEW</button> <button type="submit" value="Submit" id="sub">SUBMIT</button> <button type="reset" value="Reset" id="clear">CLEAR</button> </div> </form>

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