Skip to content Skip to sidebar Skip to footer

Make ReadOnly Textbox Non-Selectable

I have a form with a textbox that has an attribute of read-only. This isn't a big deal but I thought I would ask, so is there a way to make that textbox so that the user cannot se

Solution 1:

Try this. Its working for me. Replace @Html.EditorFor with this control.

<input type="text" value="@Model.Time" id="Time" name="Time" class="form-control" readonly />

Solution 2:

Use inline onkeydown="return false;" attribute

or if you want a javascript solution

$('#someId').keydown(function(e) {
   e.preventDefault();
   return false;
});

Solution 3:

I have used Stephen's comment as an answer and it works.

I have created a hidden input field to submit to the server, but the user will only see the disabled textbox with the value that that hidden input field is holding.


Post a Comment for "Make ReadOnly Textbox Non-Selectable"