Here is my HTML/JavaScript:
What I ended up doing - what I should have done in the first place - is adding a click handler for the submit button:
$("input[name='submitButton']").click(function(){...});