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

537
Vistas
How to submit a form on 2 different urls one after the other?

I have a form which takes some settings as input and contains 2 buttons, one to save the form and another one to save and execute the settings.

<form method="post" action="/settings/{{id}}/save">
    <!-- input fields -->
    <button type="submit">Save</button>
    <button type="submit" onclick="saveAndExecute(this)">Save and Execute</button>
</form>

I referred from this answer: https://stackoverflow.com/a/8731806, and added saveAndExecute() function to submit form to different urls by updating the action of the form.

function saveAndExecute(button) {
    const form = button.closest("form");         // To get the form object
    form.submit();                               // Save the form (save url)
    form.action = "/settings/{{id}}/execute";    // Updating the form action url
    form.submit();                               // Execute the setting
    form.action = "/settings/{{id}}/save";       // Update the action url back to original url
}

This is working fine for me, but I'm not sure if this is the correct way to submit form multiple times. Please correct me if I'm wrong, or if there are any other improvements?

Also, after submitting through Save and Execute, my page url also changes (/execute/ is appended after the page url). How can I fix this?

P.S. I'm not experienced in frontend technologies.

P.P.S. I'm not using any frontend framework/library other than jQuery.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I would implement a new save and execute method on the backend. This also saves you traffic. This method then executes the two functions synchronously one after the other. submitting the same form with diffrent actions is not clear for me.

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