Kevin Meredith
Kevin Meredith

Reputation: 41909

Preventing a Button Click's Actions

I'm working on a GUI. When a user presses "Load," a bunch of processing occurs that takes 2-3 minutes. After the "Load" processing finishes, the user clicks "Execute."

The problem is that my program crashes when the user clicks "Execute" before the "Load" processing completes. This is possible currently since there's no prevention of hitting the "Execute" as the "Load" is still processing.

Please advise a friendly user approach to preventing the user from pressing "Execute" before the "Load" is completed.

Thanks.

Upvotes: 0

Views: 63

Answers (2)

vpiTriumph
vpiTriumph

Reputation: 3166

You can use the disabled attribute on an input of type="button" to enable or disable a button. Use jQuery to add the disabled attribute when you'd like the button to be disabled.

$("#Execute").attr( 'disabled', 'disabled' );

and remove it

$("#Execute").removeAttr( 'disabled');

when you'd like it to be enabled. E.g. after your load event completes.

Upvotes: 1

Martin
Martin

Reputation: 40325

Difficult to give a definitive answer without knowing your UI environment. The simple solution would be to disable, or hide the Execute button until the Load process has completed.

Although my preferred solution would be to have the execute process check if data had been loaded, and if not execute the load before continuing with it's own thing.

If the load is a long, resource intensive procedure then you could always ask for user confirmation - but chances are that if they are asking 'to execute' and data hasn't been loaded, then loading it is the right thing to do.

Upvotes: 1

Related Questions