Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to enable and disable a textbox in jQuery in ASP.net

Tags:

jquery

c#

asp.net

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.

like image 959
Nuthan Gowda Avatar asked Nov 30 '22 13:11

Nuthan Gowda


2 Answers

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");
like image 123
bPratik Avatar answered Dec 02 '22 03:12

bPratik


To disable

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

to enable

$('#<%=txt1.ClientID %>').removeAttr("disabled");
like image 32
Talha Avatar answered Dec 02 '22 03:12

Talha