Turns out if you use:
<input type="button" onclick="function(parameters)">
instead of a button tag then it works.