Pregunta

I have a textbox on my page to accept user input and I'd like to have a couple of line showing up as read-only WITHIN the textbox as hints. For example,

(read-only) Begin Input Category: User
....
....
....
....
(read-only) End Input Category: User

Is this even possible with some trick in jQuery or CSS?

¿Fue útil?

Solución

No, you cannot make individual lines of a textbox read only.

However, you could keep a seperate copy of the original text in a variable, and every time the user types in the textbox compare and if they touched the read only parts, fix it back, but this is likely to be error prone.

A better choice would be something more like how masterpages work, where the master template defines user editable areas, and you provide a place for the user to input those user defined areas (seperate text boxes? XML delmited text?), then you can render a merged view

Otros consejos

I believe not possible. Try putting 2 labels with your read only lines, adjacent to the text box at the top and bottom with margin 0 , bottom border 0 for the top label, top border 0 for the bottom label, top and bottom border zero for the text box. The labels and the text box should be of equal length. This may give a feeling that the text box has top and bottom row readonly. While posting the form use javascript to post the data combine of top label + text box + bottom label.

Or at the most you can do is display the above text as you have shown and when user enters the cursor into the text box then erase the text. Again when he removes the cursor out (focus out of text box) then check if text box is empty, if empty then put back that text. While submitting the form you can then append and prepend the text back to the text box data if it is not there.

How about using wartermark or similar technique to make the watermark stay (vs. going away when the textbox is in focus) but read-only?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top