Prevent clicking a button multiple times

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

eddparsons
Ebase User
Posts: 53
Joined: Wed Jan 02, 2013 4:23 pm
Location: Lyndhurst, Hampshire
Contact:

Prevent clicking a button multiple times

#1

Postby eddparsons » Tue May 25, 2021 11:22 am

How do you handle users who click a button multiple times before the script on the button has time to complete? I only want the script to run once regardless of how many times the button is clicked

Is there a way to do this within Verj?
0 x

Segi
Ebase User
Posts: 649
Joined: Mon Dec 09, 2013 6:37 pm

Re: Prevent clicking a button multiple times

#2

Postby Segi » Tue May 25, 2021 7:02 pm

Yes you can do this pretty easily.

I just made a simple proof of concept that shows how this works and attached it to this post

In HTML entities for the button in my example, I put

Code: Select all

document.getElementById('testBtn').style.display = 'none'
for the click event which immediately hides the button as soon as you click on it on the client side. It won't work the way that you expect if you try to hide the button in the server side script so that's why you have to hide it on the client side.

In the script Buttonform_Button_Click, I put the command:

Packages.java.lang.Thread.sleep(5000);

to simulate a delay of 5 seconds while some kind of long running processing would normally be done then show the button after it completes.

So to answer your question, the best way to prevent the button event from firing multiple times is to hide or disable it.

Segi
Attachments
ButtonExample.zip
proof of concept
(3.32 KiB) Downloaded 198 times
0 x

eddparsons
Ebase User
Posts: 53
Joined: Wed Jan 02, 2013 4:23 pm
Location: Lyndhurst, Hampshire
Contact:

Re: Prevent clicking a button multiple times

#3

Postby eddparsons » Wed May 26, 2021 8:38 am

Perfect, thanks very much Segi!
0 x


Who is online

Users browsing this forum: No registered users and 9 guests