I have a form that has two buttons. One to edit a specific candidate after the information has been submitted, another button to just submit and add another candidate. Since there are two buttons on the screen, I need to know which one was clicked so that I can escort the user down the right path.
I am using the jQuery Validation Plugin to help me validate the form before posting it. To prevent users from double clicking the button and submitting a duplicate candidate, I am disabling the button and changing the button to "Submitting" as demonstrated here:
/* This will change the button only if the form has passed and change the button to submitting and disable it */
submitHandler: function(form) {
$('#saveandadd').click(function() {
$('#saveandadd').val('Submitting...');
$('saveandadd', this).attr('disabled', 'disabled');
form.submit();
});
$('#saveandedit').click(function() {
$("input[name='setvalue']").val('1');
$('#saveandedit').val('Submitting...');
$('saveandedit', this).attr('disabled', 'disabled');
form.submit();
So far this is nice as I can change the button that was clicked to submitting. However, I have noticed a strange problem. Either button requires two clicks to submit it.
I have setup a fiddle here: Form Validation that requires the first and last name to be filled in. You will be prompted as an error if those fields are not filled in.
Thanks in advance