K
kschneider
Assume there's a form with it's action attribute all set to post to a
URL, but without a submit control. Form submission is done via a link
and I want to prevent the classic "double submit". Ignoring the server
side of things, does anyone see any holes with the following script? It
seems to work, but I'd appreciate other eyes on it. Maybe a
try/catch/finally wrapper of some sort to be sure the link is
re-enabled in the face of an exception. I understand there are (many)
other ways to do this (e.g. temporarily "remove" the link), but I'm
mostly curious about the
this.onclick=falseFn/this.onclick=arguments.callee combo and any
potential gotchas. Thanks.
function falseFn() {
return false;
}
// this is the onclick handler for the link
function submitLinkOnclick() {
this.onclick = falseFn; // disable link to prevent double-submit
var isOkToSubmit = false;
var form = document.getElementById("form");
// logic to see if it's OK to submit form (set isOkToSubmit = true)
if (isOkToSubmit) {
form.submit();
} else {
alert("blah blah blah");
this.onclick = arguments.callee; // re-enable link
}
return false;
}
URL, but without a submit control. Form submission is done via a link
and I want to prevent the classic "double submit". Ignoring the server
side of things, does anyone see any holes with the following script? It
seems to work, but I'd appreciate other eyes on it. Maybe a
try/catch/finally wrapper of some sort to be sure the link is
re-enabled in the face of an exception. I understand there are (many)
other ways to do this (e.g. temporarily "remove" the link), but I'm
mostly curious about the
this.onclick=falseFn/this.onclick=arguments.callee combo and any
potential gotchas. Thanks.
function falseFn() {
return false;
}
// this is the onclick handler for the link
function submitLinkOnclick() {
this.onclick = falseFn; // disable link to prevent double-submit
var isOkToSubmit = false;
var form = document.getElementById("form");
// logic to see if it's OK to submit form (set isOkToSubmit = true)
if (isOkToSubmit) {
form.submit();
} else {
alert("blah blah blah");
this.onclick = arguments.callee; // re-enable link
}
return false;
}