aspdotnet-suresh offers articles and tutorials,csharp dot net, articles and tutorials,VB.NET Articles,Gridview articles,code examples of 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

JavaScript - Enable or Disable a Controls Like Button, Textbox, Checkbox

Mar 14, 2013

Here I will explain how to enable or disable a button control in JavaScript or Enable/Disable a controls in JavaScript. 

In previous articles I explained JavaScript Enable/Disable button based on text in textboxes,
jQuery Shake image on mouse over, jQuery upload multiple files using multiple file upload plugin, jQuery fancy switch on and off effects example and many articles relating to JavaScript, jQuery, Now I will explain how to enable or disable a button control in JavaScript.
To set controls enable or disable in JavaScript we need to write the code like as shown below

Enable control in JavaScript

document.getElementById('btnButton').disabled = false;
Disable control in JavaScript

document.getElementById('btnButton').disabled = true;
If you want to see it in complete example check this code

<html xmlns="">
<title>Enable or Disable a control in javascript</title>
<script language="javascript" type="text/javascript">
//function to enable button if two textboxes contains text
function SetButtonStatus() {
var txt = document.getElementById('txtfirst');
//Condition to check whether user enters text in two textboxes or not
if (txt.value.length >= 1)
document.getElementById('btnButton').disabled = false;
document.getElementById('btnButton').disabled = true;
<input type="text" id="txtfirst" onkeyup="SetButtonStatus(this,'btnButton')"/>
<input type="button" id="btnButton" value="Button" disabled="disabled" />
Live Demo

For live demo enter text in textbox whenever we enter text button will enable otherwise it’s in disable mode

Enter Text

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest,, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email


Arun Mohan said...

Wow ..Super Bhai.. Really helpful.

Anonymous said...


Give your Valuable Comments

Other Related Posts

© 2015 All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.