2

I'm trying to disable textbox using jquery:

$('#<%=txtFrom.ClientID %>').attr('disabled', true);

It looks as disabled: image, but actually it's not, I can write there. Why?

UPDATE: Fixed by adding input in the code:

$('#<%=txtFrom.ClientID %> input').attr('disabled', true);
8
  • 1
    If what you want is just read only: stackoverflow.com/questions/1306708/… Commented Feb 14, 2013 at 21:30
  • 4
    Seems to work for me, but prop() is actually the preferred method, and did you remember document.ready ? Commented Feb 14, 2013 at 21:31
  • Of course, I used after document.ready, actually after Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded. Commented Feb 14, 2013 at 21:33
  • Mario, you mean I should use ReadOnly instead disabled? Disabled worked for me before. Commented Feb 14, 2013 at 21:34
  • 1
    Sounds like your jQuery selector was wrong, punch $('#<%=txtFrom.ClientID %>) into the browser console debug window and see what you get. Commented Feb 14, 2013 at 21:39

1 Answer 1

1

You need to do that:

$('#YOUR_ELEMENT_ID').attr("disabled", "disabled");
Sign up to request clarification or add additional context in comments.

1 Comment

Why? If it works with true and false? I prefer to use boolean value, because actually I use some condition to enable and disable it.

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.