Solved

Disable a button for 2 seconds

Posted on 2014-01-10
8
410 Views
Last Modified: 2014-01-11
I just want a suggestion from someone with experience.  I would like to disable a button ( and possibly make it grey) for a second or two after it was clicked.  After 2 seconds it should re-enable so if the user really wants to click it multiple times they can.
Thank you in advance or your advice.
0
Comment
Question by:wilfordrocks
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 12

Expert Comment

by:ktaczala
ID: 39772899
Set up a separate thread(using BackgroundWorker) to count for 2 seconds.  Then when the thread completes, re-enable the button.  By putting it on a separate thread normal operation will not pause in your application.
0
 
LVL 40
ID: 39773345
Put a Timer Control on the Form and set its Interval property to 2000.

In the Click event of the button, start the timer and disable the button:

            Timer1.Start()
            Button1.Enabled = False

In the Tick event of the timer, reenable the Button

            Button1.Enabled = True
0
 

Author Comment

by:wilfordrocks
ID: 39773370
That is kind of a windows way of doing it.  I suspect Java or jquery has a browser way of doing it.  thanks for your input.  I will leave the question open a little longer.
0
 
LVL 40
ID: 39773378
Ooops. Sorry, I did not see your Tags.

Try to be more precise in your Topics. ExpertExchange uses the topics to flag experts, and you have more chances of having your question falling in the right hands if you specify less general topics.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39773515
With plain javascript you could use something like this:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>EE Q_28335925</title>

<script type='text/javascript'>
var g_sbm = null;
function temp_disable(sbm, tm) {
    g_sbm = sbm;
    toggle_sbm();
    setTimeout(toggle_sbm, tm);
}
function toggle_sbm() {
    g_sbm.disabled = !g_sbm.disabled;
}
</script>

</head>
<body>

<form name="frm" action="" method="post" onsubmit="return false;">
  <input name="name">
  <input name="sbm" id="sbm" type="submit" onclick="temp_disable(this, 2000)">
</form>

</body>
</html>

Open in new window

0
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 39773528
quick addition for the color:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>EE Q_28335925</title>

<script type='text/javascript'>
var g_sbm = null, g_sbmcol;
function temp_disable(sbm, tm) {
    g_sbm = sbm;
    g_sbmcol = g_sbm.style.backgroundColor;
    toggle_sbm();
    setTimeout(toggle_sbm, tm);
}
function toggle_sbm() {
    g_sbm.disabled = !g_sbm.disabled;
    g_sbm.style.backgroundColor = g_sbm.style.backgroundColor == g_sbmcol ? 'gray' : g_sbmcol;
}
</script>

</head>
<body>

<form name="frm" action="" method="post" onsubmit="return false;">
  <input name="name">
  <input name="sbm" id="sbm" type="submit" onclick="temp_disable(this, 2000)" style="color: white; background-color: green;">
</form>

</body>
</html>

Open in new window

0
 

Author Comment

by:wilfordrocks
ID: 39773923
This is beautiful and elegant.  Thank you.
Just to make sure I understand the variable names.
'g_'  means global?
'sbm'  stands for submit?
'col'  is color?

Again, thank you.
0
 
LVL 35

Expert Comment

by:Robert Schutt
ID: 39773929
yep, 3 out of 3 :-)

And thank you!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now