Home > database >  replace the form with a message -not with PHP
replace the form with a message -not with PHP

Time:12-10

I have this code

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

I want not to do this alert message.I want to replace the form giving it this message the message has been send

CodePudding user response:

Put the form in a div, and assign the innerHTML of the DIV to replace the form.

Also, you need to return false; in the onsubmit code to prevent the form from submitting to the server.

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>

  • Related