Tengo un archivo HTML que tiene dos secciones. Una sección tiene un formulario dentro de ella. Y el otro tiene un mensaje. Si el usuario envía el formulario, aparece un mensaje y habrá otro botón que el usuario debe presionar para completar el envío.
¿Hay alguna forma de vincular un botón para que el usuario tenga que presionar el otro botón para completar el trabajo del botón original?
<section> <form> <input>... <button> // User presses the first submit button </button> </form> </section> <div> <button> // User has to press this button next inorder to complete the form </button> <div>const form = document.querySelector("form"); // First grab the form const btn2 = document.getElementById("button2"); // Second button, make sure to add the id or any other proper selector let isSubmitted = false; // Once form will be submitted from inside // we will prevent the default behaviour of it so it does not do anything other than // marking isSubmitted as true, so this can be checked in other actions form.addEventListener("submit", (e) => { e.preventDefault(); isSubmitted = true; }); // Once the form is submitted once, only then // trigger programmatically the actual behaviour btn2.addEventListener("click", () => { if (isSubmitted) { form.submit(); } }); De esta forma, también puede jugar con la variable isSubmitted y volver a marcarla como falsa cada vez que alguien realice una acción que requiera una confirmación adicional del propio formulario.