1

I've following textbox which is initially disabled:

<input id="txtCustFName" name="txtRCustFName" type="text" required disabled="true"/>

on click on following anchor tag i m calling the js to enable the above text box: HTML: Enable

JS:

EnableTxt()
{
    document.getElementById("txtCustFName").disabled = false;
}

But this code is not working. I am not able to enable text box.

How can I do this?

Saurabh Palatkar
  • 3,242
  • 9
  • 48
  • 107
  • 1
    The solution is posted here: http://stackoverflow.com/questions/8484181/how-to-enable-a-disabled-text-field – Saravanan May 13 '13 at 11:03

7 Answers7

2

Removing the attribute worked allowed me edit the content of the textbox :

document.getElementById("questionnaireText").removeAttribute("disabled");

To set the textbox to disabled use :

document.getElementById("questionnaireText").setAttribute("disabled", true);
Jouby
  • 2,196
  • 2
  • 21
  • 33
wale A
  • 81
  • 1
  • 7
1

You can enable/disable using this:

function EnableTxt() {
       document.getElementById( '<%=txtRCustFName.ClientID%>' ).disabled = 'false';
   }
Altaf Sami
  • 846
  • 5
  • 10
  • 21
0

Try this:-

document.getElementById("txtCustFName").setAttribute("disabled", false);
Kiren S
  • 3,037
  • 7
  • 41
  • 69
0

you can do that by setting style using java script

for example:

document.getElementById("txtCustFName").setAttribute("style", "disabled:disabled"); 
Aijaz Chauhan
  • 1,511
  • 3
  • 25
  • 53
0

JavaScript

function myfunction(event) {
            alert('some anchor clicked');
            $('#txtCustFName').prop("disabled",false);
            return false;
      };
$(document).ready(function(){
          $('#myanchorid').click(myfunction);
          $('a.anchorclass').click(myfunction);
          $('#anchorlist > a').click(myfunction);
});

HTML

<html xmlns="http://www.w3.org/1999/xhtml" >
<script type="text/javascript" id="Script1" src="jquery-1.8.2.min.js"></script>
<script type="text/javascript" id="myScript" src="myScript.js"></script>

<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <a id="myanchorid" href="#">Click Me</a><br />
    <a class="anchorclass" href="#">Click Me</a><br />
<input id="txtCustFName" name="txtRCustFName" type="text" required disabled="true"/><br />
    <div id="anchorlist">
          <a href="#">Click Me</a>
          <a href="#">Click Me</a>
          <a href="#">Click Me</a>
    </div>
    </div>
    </form>
</body>
</html>

Try this....this will resolve your problem...

Anna.P
  • 903
  • 1
  • 6
  • 17
0

Try this:

function EnableTxt() {
   $("#txtCustFName").prop("disabled", false);
}

Here "prop" is used for property/attribute of the tag.

Ramakant Shukla
  • 137
  • 1
  • 10
-1

You should use the attribute of the textbox.

jQuery:

($this.attr('disabled')) $this.removeAttr('disabled');

Please note that this is not supported in IE6

Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
Samjongenelen
  • 401
  • 4
  • 18