How actually you are making call to this function ??
It has to be either of these -
<form method="post" onsubmit="return functionName()">
...
<input type="submit" value="Submit">
</input></form>
or (inline or within the function invoked on click of the button)
<form method="post">
...
<input type="submit" value="Submit" onclick="return functionName()">
</input></form>