Forums

Submit Confirmation

itpates 26 Oct, 2018
I am trying to prevent unintended submissions of a form when the Enter key is accidentally pressed. I tried in abject futility to block the Enter key - code 13 and 10 - so am revisiting a simple confirmation popup. The code I have works - if Enter is pressed or Submit button clicked, it does create a pop-up. If I click OK, it submits the form as expected. But if I click Cancel, it hangs the form altogether. Displays a faded version of the form and all data typed in it, that is completely unresponsive. The only way to get the form to work again is to refresh the document, which deletes everything entered. Any ideas? Here are two options I tried - both exhibits identical results:
jQuery('#display-section1').submit(function() {
var status = confirm("Click OK to Submit?");
if(status == false){
return false;
} else {
return true;
}
});

jQuery(document).submit(function() {
var status = confirm("Click OK to Submit?");
if(status == false){
return false;
} else {
return true;
}
});
itpates 26 Oct, 2018
I get the same results if I try something like this too. I want it to go back to the form with the data intact so the user can finish it, or correct it before submitting again:
jQuery('#display-section1').submit(function() {
var c = confirm("Click OK to continue?");
return c;
});
GreyHead 29 Oct, 2018
Answer
Hi ipates,

I recall that there are problems in capturing Enter key presses because of slightly different browser behaviours.

It may be simpler to prevent the from from submitting before the key data is entered. You could:

+ add a checkbox above the Submit button asking the user to check their submission and disable the Submit button until this is checked.

+ add a custom validation function somewhere on the form that checks that key data is complete.

Bob
ITadminguy 30 Oct, 2018
Bob is correct.

I left the submit button alone as it normally is (there is no disable setting).

Instead, if you have a checkbox "agree to terms" or whatever just above the submit button, go in and create a "select" event to enable and "unselect" event to disables the submit button.

When your form loads the checkbox is unchecked so the submit button will be disabled with have a 50% or so color discoloration-transparency. When you check the checkbox, the the button turns to normal color and can submit.

itpates 30 Oct, 2018
Thanks. I just did the checkbox method on one form, and inserted a blank space at the top of a drop-down on another form. Both methods work great.
GreyHead 30 Oct, 2018
2 Likes
Hi ipates,

Instead of a blank space at the top of the drop-down you can use a line with no value e.g. =Please choose

Bob
This topic is locked and no more replies can be posted.