4

I have a Textbox where I need to disable or enable that on some Conditions.

var stat = "any interger"
    if (statId != 1) {
     $('#<%=txt1.ClientID %>').attr("disabled", "disabled");
     } 
    else {
    $('#<%=txtBQty.ClientID %>').attr("enabled", "enabled");
     }

This one will work but after disable if the condition returns false also means It won't enable the textbox.

1
  • What is your question? Please explain. Commented Nov 20, 2012 at 10:19

4 Answers 4

11

enabled is not a valid attribute for textboxes. So the following will have no effect:

$('#<%=txtBQty.ClientID %>').attr("enabled", "enabled");

Instead use

$('#<%=txtBQty.ClientID %>').removeAttr("disabled");
Sign up to request clarification or add additional context in comments.

Comments

8

To disable

$('#<%=txt1.ClientID %>').attr("disabled", "disabled");

to enable

$('#<%=txt1.ClientID %>').removeAttr("disabled");

Comments

2

To disable use :

$('#<%=txt1.ClientID %>').attr("disabled", "disabled");

to enable just clear the value

$('#<%=txt1.ClientID %>').attr("disabled", "");

Comments

1

Here's how you can do if it is in latest version of jQuery

var stat = "any interger";
if (statId != 1) {
     $('#<%=txt1.ClientID %>').prop("disabled", true);
} 
else {
    $('#<%=txtBQty.ClientID %>').prop("disabled", false);
}

If you have to use .attr(), you can disable with $(selector).attr('disabled','disabled') and enable with $(selector).removeAttr('disabled')

1 Comment

Got this error-"Object doesn't support this property or method"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.