OK, I figured it out and I am going to post the solution in case of someone else bump with the same problem.
The solution to avoid it therefore is to replace this:
<input type="submit" onclick="MyCustomSearch()"/>
<input type="button" value="Search" onclick="MyCustomSearch()"/>
Actually I am ALWAYS forgetting about this issue and repeating the same mistake again and again...