You can enable/disable using this:
function EnableTxt() {
document.getElementById( '<%=txtRCustFName.ClientID%>' ).disabled = 'false';
}
Pregunta
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?
Solución
You can enable/disable using this:
function EnableTxt() {
document.getElementById( '<%=txtRCustFName.ClientID%>' ).disabled = 'false';
}
Otros consejos
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);
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.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...
Try this:
function EnableTxt() {
$("#txtCustFName").prop("disabled", false);
}
Here "prop" is used for property/attribute of the tag.
You should use the attribute of the textbox.
jQuery:
($this.attr('disabled')) $this.removeAttr('disabled');
Please note that this is not supported in IE6