I am using a combination of knockout and jquery and I would like to know how I can make a textbox readonly in either knockout or jquery
Asked
Active
Viewed 4,381 times
0
-
`$(yourTextBox).prop('readonly', true);` – Feb 20 '18 at 09:31
-
1@StephenMuecke Please don't post answers as comments – Scoots Feb 20 '18 at 09:34
-
1He most likely knew it was about to be closed as a duplicate and was trying to help the OP without getting in the way of the garbage collector – Rory McCrossan Feb 20 '18 at 09:46
2 Answers
0
Hi there you have not shown us what you have tried so far, however, I have listed a knockout and jquery example that might be useful to you. You can also have a look at this link for further clarification.
<!-- ko if: if your condition is met -->
<input type="text" class="input-xlarge" data-bind="value: texboxValue" id="textboxID" />
<!-- /ko -->
<!-- ko ifnot: if your condition is not met -->
<input type="text" class="input-xlarge" data-bind="value: texboxValue" id="textboxID" textboxName" readonly />
<!-- /ko -->
Then on the jQuery side:
// this will make you textbox readonly
$("#textboxID").attr('readonly', 'readonly');
// this will remove the readonly attribute from your text box read/writeable
$("#textbox").removeAttr('readonly');

Rory McCrossan
- 331,213
- 40
- 305
- 339

Zidane
- 1,696
- 3
- 21
- 35