<button type="submit" class="validate btn btn-primary" onclick="myfunction()"><?php echo JText::_('JSUBMIT'); ?></button>"myfunction()" and then the "Joomla.submitform()".
At least, that's how it worked fr me, try it.
Let as know the result.
var Myvar = {};
Myvar.submitbutton = Joomla.submitbutton;
Joomla.submitbutton = function(task) {
... custom code here ...
Myvar.submitbutton(task);
}