Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
16
rated 0 times [  23] [ 7]  / answers: 1 / hits: 81809  / 13 Years ago, sat, march 10, 2012, 12:00:00

How to properly enable/disable input field on click with jQuery?



I was experimenting with:



$(#FullName).removeAttr('disabled');


which removes disabled=disabled from this input field:



<input id=FullName style=width: 299px value=Marko disabled=disabled />


But how to add it again with click on another button or how to disable input field on click?


More From » jquery

 Answers
68

For jQuery version 1.6+ use prop:



$('#elementId').click(function(){
$('#FullName').prop('disabled', truefalse);
});


For older versions of jQuery use attr:



$('#elementId').click(function(){
$('#FullName').attr('disabled', 'disabled''');
});

[#86931] Friday, March 9, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kerryoliviaa

Total Points: 221
Total Questions: 102
Total Answers: 117

Location: Sint Maarten
Member since Tue, Mar 29, 2022
2 Years ago
kerryoliviaa questions
;