3.2.0

Best way to prevent onClick event firing twice?

Hi everyone

I am using AW controls for displaying a form (for editing a row in a grid) and I have experienced that on a slow performing server-client network, if the user presses the submission button twice quickly, the form can be submitted twice.

I understand that preventing this is standard javascript stuff, but I'm finding some difficulties. I have thought of trying to disable the button after it's been clicked (see a different post on disabling buttons) without much joy. I'm also trying to capture if the button has been pressed once and then preventing it firing the onClick a second time in the following way:

submit_button = new AW.UI.Button;
submit_button.onClick= function(){
if (submitted) return false;
var submitted = true;
perform_validation_and_submission();
}


.. but again, I can't see that this is working (still seem able to submit twice). Is the above a valid approach to the problem, or can anyone suggest anything else?

Thanks
Will
Will
July 19,
You have to declare you status variable ('submitted') outside of the function (othervise it is local, i.e. loses value on exit and re-initialized on the next call).
Alex (ActiveWidgets)
July 19,
or use object property, i.e. this.submitted
Alex (ActiveWidgets)
July 19,

This topic is archived.

See also:


Back to support forum