On an HTML page, how exactly do I add a click handler for a button on a form? In Java it's

<INPUT TYPE="submit" NAME="btnSave" VALUE="Save" onClick=OnClickBtnSave>

I want a subroutine to be called before the form does its POST thing.

Or, can the form's ACTION be set to call a subroutine instead of going to an URL or script?