Solved

Disable a button for 2 seconds

Posted on 2014-01-10
8
417 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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
 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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