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

233
Vistas
How to change form action when a 'preview' button is clicked

I am trying to get a different page, preview.php to show when the Preview Button is clicked, by changing the action of the form. The preview button should lead to another page where I can view the inputs from the file and maybe have options to submit or go back.

The other buttons, submit and clear work however the preview button does not seem to be working. It stays on the same page even after clicking the button.

As a test I put in some alerts. 'here1' and 'here2' alerts work, but 'here3' alert does not work, making me believe the changeAct() function is not reached. How can I fix this so the form action can be changed?

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