Stop form refreshing page on submit

You can prevent the form from submitting with

$("#prospects_form").submit(function(e) {
    e.preventDefault();
});

Of course, in the function, you can check for empty fields, and if anything doesn't look right, e.preventDefault() will stop the submit.

Without jQuery:

var form = document.getElementById("myForm");
function handleForm(event) { event.preventDefault(); } 
form.addEventListener('submit', handleForm);

Add this onsubmit="return false" code:

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

That fixed it for me. It will still run the onClick function you specify


Replace button type to button:

<button type="button">My Cool Button</button>

One great way to prevent reloading the page when submitting using a form is by adding return false with your onsubmit attribute.

<form action="#" onsubmit="yourJsFunction();return false">
    <input type="text"/>
    <input type="submit"/>
</form>