title: Enable and disable button using javascript and asp.net
body: <p>I am checking if user exists in database if exists I am showing message as "existed user" and then I need to disable the signup button if not I need to enable it.</p>
  
  <p>I am unable to enable and disable the sign Up button.</p>
  
  <p>Can anyone help me in this issue?</p>
  
  <p>Here is my code:</p>
  
  <pre><code> &lt;script type="text/javascript"&gt;
       $(function () {
           $("#&lt;% =btnavailable.ClientID %&gt;").click(function () {
               if ($("#&lt;% =txtUserName.ClientID %&gt;").val() == "") {
                   $("#&lt;% =txtUserName.ClientID %&gt;").removeClass().addClass('notavailablecss').text('Required field cannot be blank').fadeIn("slow");
  
               } else {
                   $("#&lt;% =txtUserName.ClientID %&gt;").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
                   $.post("LoginHandler.ashx", { uname: $("#&lt;% =txtUserName.ClientID %&gt;").val() }, function (result) {
                       if (result == "1") {
                           $("#&lt;% =txtUserName.ClientID %&gt;").addClass('notavailablecss').fadeTo(900, 1);
                         document.getElementById(#&lt;% =btnSignUp.ClientID %&gt;').enabled = false;
                       }
                       else if (result == "0") {
                           $("#&lt;% =txtUserName.ClientID %&gt;").addClass('availablecss').fadeTo(900, 1);
                          document.getElementById('#&lt;% =btnSignUp.ClientID %&gt;').enabled = true;
                       }
                       else {
                           $("#&lt;% =txtUserName.ClientID %&gt;").addClass('notavailablecss').fadeTo(900, 1);
                       }
                   });
               }
           });
  
           $("#&lt;% =btnavailable.ClientID %&gt;").ajaxError(function (event, request, settings, error) {
               alert("Error requesting page " + settings.url + " Error:" + error);
           });
       });
  &lt;/script&gt;
  </code></pre>