Solved

Disable a button for 2 seconds

Posted on 2014-01-10
8
412 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

23 Experts available now in Live!

Get 1:1 Help Now