Hi, I would like to ask for help with a piece of javascript code intended to prevent double form submit which I cannot get to work with
JSF.
First, I tried simply returning false from a javascript function when a user clicks twice. I have a variable requestSubmitted on every page, initially set to true, and a function which is called on form submit containing he following:
This does not work, as in the case of a second submission - despite of the "return false" - the form is submitted anyway, and I get duplicate requests.
Second, I tried disabling the button, and that in two different places. First time, in "if" part, after a form.submit(). In that case, there was no form submit at all:
if (!requestSubmitted ) {
requestSubmitted = true;
form.submit();
submitButton.disabled = true;
return true;
} else {
alert("duplicate submit");
}
Second time, in the "else" part. In that case, the form was not submitted either, i.e. not even the necessary first submit was carried out:
if (!requestSubmitted ) {
requestSubmitted = true;
form.submit();
return true;
} else {
submitButton.disabled = true;
alert("duplicate submit");
}
I suppose these problems come from JSF working with javascript internally, but I don't know what to do in this case. Does anybody have an idea or can explain what's going on?
thanks,
Sigrid