spacer
Yehuda Shiran November 24, 2001
Disabling A Button
Tips: November 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management
Sometimes, you may want to disable a button from JavaScript. You need to, for example, when the service called by the button is not available. A Web service called synchronously should not be called again while working on its previous call.

Play around with the following two buttons. Toggle the second button with the first one:





Here is how the buttons are defined:

<BUTTON ID="b1" onclick="toggleOtherButton()">Toggle Other Button</BUTTON><BR><BR>
<BUTTON ID="b2" onclick="sayHello()" disabled>Say Hello</BUTTON><BR><BR><BR><BR>
The first button toggles the disability of the button below it, through the toggleOtherButton() function:

function toggleOtherButton() {
  if (b2.disabled) {b2.disabled = false;}
  else b2.disabled = true;
}
Here is the whole JavaScript code:

<SCRIPT LANGUAGE="JavaScript">
<!--
function toggleOtherButton() {
  if (b2.disabled) {b2.disabled = false;}
  else b2.disabled = true;
}

function sayHello() {
  alert("Hello there");
}
// -->
</SCRIPT>

People who read this tip also read these tips:

Look for similar tips by subject:

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Administering MySQL Databases on the Web Using PHP · Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
So what is an Oracle Nested Table? · E-Discovery Architectures 101 · eBay Embraces Big Sellers, Cyber Monday Trends