Skip to content

JavaScript form onsubmit return false

  • by

JavaScript form onsubmit return false means do nothing on submit. In short, return false will cancel the event (or in this case, cancels the form submission).

<form name="foo" onsubmit="return false">

JavaScript form onsubmit return false

Simple example code validation returns false – your form will not submit and will not redirect too and When it returns true – your form will submit and will redirect (actually it’s a part of submit) id you have mentioned in action.

<!DOCTYPE html>
  <script type="text/javascript">
   function myFunctionName() {
    if (document.myForm.myText.value == ''){
      return false; 
    return true;

<form name="myForm" onSubmit="return myFunctionName()">
  <input type="text" name="myText">
  <input type="submit" value="Click Me">



JavaScript form onsubmit return false

If you are using a button instead of submit as in my case below:

 <form name="myForm" onSubmit="myFunctionName(); return false">
    <input type="text" name="myText">
    <input type="button" value="Click Me" onclick="myFunctionName()">

Do comment if you have any doubts or suggestions on this Js submit topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *