Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 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
Introduction

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

Description:
  
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, asp.net. 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="http://www.w3.org/1999/xhtml">
<head>
<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;
else
document.getElementById('btnButton').disabled = true;
}
</script>
</head>
<body>
<div>
<input type="text" id="txtfirst" onkeyup="SetButtonStatus(this,'btnButton')"/>
<input type="button" id="btnButton" value="Button" disabled="disabled" />
</div>
</body>
</html>
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 Asp.net, C#.net, 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

2 comments :

Unknown said...

Wow ..Super Bhai.. Really helpful.

Anonymous said...

great

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

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