For any lost souls out there with the same problem.
Put your function with ‘onsubmit’ in the tag.
In your function use the following code to prevent the page from generating a request
and resetting your form:
if(event.preventDefault) event.preventDefault(); else event.returnValue = false;