admin管理员组

文章数量:1290765

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?

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?

Share Improve this question asked May 13, 2013 at 11:01 Saurabh PalatkarSaurabh Palatkar 3,38412 gold badges52 silver badges112 bronze badges 1
  • 1 The solution is posted here: stackoverflow./questions/8484181/… – Saravanan Commented May 13, 2013 at 11:03
Add a ment  | 

7 Answers 7

Reset to default 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);

You can enable/disable using this:

function EnableTxt() {
       document.getElementById( '<%=txtRCustFName.ClientID%>' ).disabled = 'false';
   }

Try this:

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

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

Try this:-

document.getElementById("txtCustFName").setAttribute("disabled", false);

you can do that by setting style using java script

for example:

document.getElementById("txtCustFName").setAttribute("style", "disabled:disabled"); 

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/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...

You should use the attribute of the textbox.

jQuery:

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

Please note that this is not supported in IE6

本文标签: cEnabling text box using javascriptStack Overflow