Web Tools Table Maker3schools TranslateImage CompressorFavicon Icon GeneratorCrop & Resize Image
Apu
Apu June 03, 2023 › #Form #HowTo

How to submit a form without refreshing the page using JavaScript.

How to submit a form without refreshing the html page using JavaScript.

Whenever you create a html form and want to submit that form, the page automatically refreshes. But if you want to submit a form without page refresh using JavaScript, then in this article, I'm going to share how you can prevent page reload on form submit in Js.

Sometimes, we want to execute a function without refreshing the page. So we have to prevent the html page to reload by using return false;.

return false; prevents the default behaviour. In this example, it prevents to submit the form.
Submit a form without refreshing
<form action="#" onsubmit="myFunction();return false">
    <input type="text" placeholder="Enter Your Name"/>
    <input type="submit" value="submit"/>
</form>
<script>
   function myFunction() {
   alert("Form Submitted") ;
   }
</script>
Try it Yourself »
save
listen
AI Answer
Write Your Answer
loading
back
View All