noahd1
11-07-2003, 07:43 PM
I'm having trouble with what should be a simple javascript. The script's purpose is to stop people from submitting a form more than once on the same page. I'm not talking about a user hitting back and submitting again (this is a different unrelated issue). I'm talking about a specific situation where, if there's a long enough wait after hitting submit, or if the user is crazy and starts rapid-fire pressing submit, there's a chance that mulitple requests will be sent to the server. Bad news.
Has anyone dealt with this problem before and how have they dealt with it?
The most obvious solution did not work. Something like this:
isSubmitted = false;
function submitOnce(theForm)
{
if (isSubmitted) return;
isSubmitted = true;
theForm.submit();
}
in my case, a link calls it (as below) but could just as well be from a onSubmit call or something.
<a href="javascript:submitOnce(document.myform)">go</a>
The problem with this code is, if you rapid fire click on the link it doesn't do anything...it never submits....(platorm: WindowsNT, IE 5.5)...it just kind of hangs. If you double click, it does its job sometimes (not always), but it fails consistantly on rapid fire clicks.
I've tried other little solutions, including changing the href of the link after clicking on it, trying to disable the link, but can't get any alternative solutions to work. The best i got is to make the link wholly disappear after clicking on it once! Not really the best solution....
Any ideas/previous experience with this issue to relate?
Thanks,
Noah
Has anyone dealt with this problem before and how have they dealt with it?
The most obvious solution did not work. Something like this:
isSubmitted = false;
function submitOnce(theForm)
{
if (isSubmitted) return;
isSubmitted = true;
theForm.submit();
}
in my case, a link calls it (as below) but could just as well be from a onSubmit call or something.
<a href="javascript:submitOnce(document.myform)">go</a>
The problem with this code is, if you rapid fire click on the link it doesn't do anything...it never submits....(platorm: WindowsNT, IE 5.5)...it just kind of hangs. If you double click, it does its job sometimes (not always), but it fails consistantly on rapid fire clicks.
I've tried other little solutions, including changing the href of the link after clicking on it, trying to disable the link, but can't get any alternative solutions to work. The best i got is to make the link wholly disappear after clicking on it once! Not really the best solution....
Any ideas/previous experience with this issue to relate?
Thanks,
Noah