Want HTML form submit to do nothing

Solution 1:

By using return false; in the JavaScript code that you call from the submit button, you can stop the form from submitting.

Basically, you need the following HTML:

<form onsubmit="myFunction(); return false;">
    <input type="submit" value="Submit">
</form>

Then the supporting JavaScript code:

<script language="javascript"><!--
    function myFunction() {
        // Do stuff
    }
//--></script>

If you desire, you can also have certain conditions allow the script to submit the form:

<form onSubmit="return myFunction();">
    <input type="submit" value="Submit">
</form>

Paired with:

<script language="JavaScript"><!--
    function myFunction() {
        // Do stuff
        if (condition)
            return true;

        return false;
    }
//--></script>

Solution 2:

<form id="my_form" onsubmit="return false;">

is enough ...

Solution 3:

It also works:

<form id='my_form' action="javascript:myFunction(); return false;">

Solution 4:

How about

<form id="my_form" onsubmit="the_ajax_call_function(); return false;">
 ......
</form>