How to avoid double requests from a form?
Hello guys!We got an application where we got a bug reported that there seems like the user manage to do som doubleklicking and send a form twice.
(At the server we see in the log that ther has been two identically request at the same time (or almost the same time) before the server has respond to the first.)
The submiting of the form is handled by the follwing javascript.
How ever me my self has not been able to reproduce the twice-submitting.
What do you think guys is this possible that a user can send a form twice before the server has respond to the first.
And do you see some nice way to handle this, perhaps a disable of some button before (or after) the submit.
All suggestions is welcome!
function checkChoice(button)
{
var buttonText = button.value;
var confText = "";
if(buttonText == "A")
{
confText = "AAA";
}
else if(knapptext == "B")
{
buttonText = "BBB";
}
return confirm(confText);
}
function sendToServer(button)
{
if(checkLength(button.form.friText))
{
setButtonText(button);
}
}
function checkLength(area)
{
var text = area.value;
if(text.length > 255)
{
alert("Maximum length is 255. No you got " + text.length + " chars.");
return false;
}
return true;
}
function setButtonText(button)
{
button.form.buttonText.value = button.value;
button.form.submit();
}
In the form in the jsp we got;
<html:hidden property="buttonText" value="" />
<textarea name="fritext"></textarea>
<html:button property="sparaknapp" onclick="if(checkChoice(this)){sendToServer(this);}" value="<%=MyDTO.getButtonText()%>" />