Google Chrome Handles click event of submit button “differently”.

Well, chrome, you are still my favorite browser, but you are handling the click event improperly. I noticed this after I was not getting any error messages and my form was not posting. Basically, if you do something like this:


$(document).ready(function () {=
//hook into title click culture to enable toggling of culture section
$('input[type="submit"]').on('click',
function () {
$('input[type="submit"]')
.attr('disabled', 'disabled')
.attr('cursor', 'wait');

return true;
});
});

Google Chrome assumes that you want to handle, not only the click event, but also the submit event. Apparently Chrome gets offended if you want to do a quick bit of formatting before you submit a form. Essentially, chrome abdicates all responsibility for everything that happens after the click event.

you – “Hey Chrome, I would like to disable that button and then submit the form.”
Chrome – “FINE! You don’t like how I submit a form, YOU DO IT!”

Anyway, this was really obnoxious to find (long story), but it is an easy fix. Just submit the form within the click event and all is well. I have not attempted to return false or prevent double submission, but so are, it hasn’t been an issue.

$(document).ready(function () {

//hook into title click culture to enable toggling of culture section
$('input[type="submit"]').on('click',
function () {
$('input[type="submit"]')
.attr('disabled', 'disabled')
.attr('cursor', 'wait')
.closest('form').submit();
});
});

This entry was posted in Development. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *