Wednesday, January 16, 2008

Javascript: How to prevent double clicks on submit button

This solution uses timers, so in accidental clicks which do not lead into postback it allows to resubmit after period is over



/* This disables Double clicks on submit buttons */
var currentClick;
var timerSet;

function ClearClick()
{
currentClick = '';
timerSet = false;
}

function DC(id)
{
var retVal = !(id == currentClick);
currentClick = id;

if (!timerSet)
{
setTimeout('ClearClick()',10000);
timerSet = true;
}
return retVal;
}

No comments: