tengo este codigo
<!DOCTYPE html> <html> <body> <p>This example demonstrates how to assign an "onsubmit" event to a form element.</p> <p>When you submit the form, a function is triggered which alerts some text.</p> <form action="/action_page.php" onsubmit="myFunction()"> Enter name: <input type="text" name="fname"> <input type="submit" value="Submit"> </form> <script> function myFunction() { alert("the message has been send"); } </script> </body> </html>No quiero hacer este mensaje de alerta. Quiero reemplazar el formulario dándole este mensaje. El mensaje ha sido enviado.
Coloque el formulario en un div y asigne el innerHTML del DIV para reemplazar el formulario.
Además, debe return false; en el código onsubmit para evitar que el formulario se envíe al servidor.
function myFunction() { document.getElementById("formdiv").innerHTML = "This form has been submitted"; } <!DOCTYPE html> <html> <body> <p>This example demonstrates how to assign an "onsubmit" event to a form element.</p> <p>When you submit the form, a function is triggered which displays some text.</p> <div id="formdiv"> <form action="/action_page.php" onsubmit="myFunction()"> Enter name: <input type="text" name="fname"> <input type="submit" value="Submit"> </form> </div> </body> </html>