0

i know <textarea name="textarea" disabled="disabled">dsds</textarea> can disable write in the textarea ,

but how to disable one line i want to disable in the textarea ?

not all line

thanks

zjm1126
  • 34,604
  • 53
  • 121
  • 166
  • 1
    That sounds like a really weird thing to do, in terms of user interface design. What is the situation? – Pointy Nov 25 '10 at 20:52
  • Why not split it out in two textareas or something like that. This is really weird indeed – Harmen Nov 25 '10 at 20:55
  • yes weird. I have wondered about disabling selected rows/columns in google spreadsheet however based on user priviledges. Would have been very useful for our lunch calculation sheet we have. – Sandeepan Nath Nov 25 '10 at 21:11

2 Answers2

1

That's not possible without JavaScript, even then:

  1. You need to enable contentEditable
  2. You need to write your own editor...
  3. You need to figure out what happens if someone deletes or inserts a line and therefore moves the disable one around
  4. You need to figure out what to do when someone hits enter in the line above the disabled one or backspace at the beginning of the line below the disabled one...

To sum it up, a textarea is the wrong approach here, better use multiple input's for whatever you want to do here, of course you will need to make it look like it's one textarea and you'll still need some JavaScript to make return work as expected (?), but then again you didn't specify what you want to do with this stuff.

Ivo Wetzel
  • 46,459
  • 16
  • 98
  • 112
  • i want to write word on where i clicked in a textarea, not only on the Beginning of the textarea , so i have to Fill many spaces in some place , and the spaces cant be deleted . – zjm1126 Nov 25 '10 at 23:15
  • @zjm1126 updated my answer. try it and let me know if it works – Sandeepan Nath Nov 27 '10 at 11:45
0

Yes, use multiple input texts appear like a single text area, let's call it fake text area. That way disabling one would be easy.

  • Do not put any margin in between them and no border, all having same width.
  • Assign incremental ids to each one - like input-1,input-2 etc.
  • If you want to prefill some text into the fake textarea, calculate the maximum length that can be accomodated into a single input and fill line by line using javascript (jquery would be better).

  • When cursor is at the end of an input text and enter is pressed, take cursor to next text input. Define a function for every such possibility and call it.

  • On posting the form, append the input values together to get the actual value of the faked text area.

I guess there may be difficulties in faking a scrollbar for such a textarea but once implemented, should work fine. Any existing plugins like this?

Updates - For handling cursor positions, refer these things. I did not try myself but may be useful - Jquery Caret position and How to get cursor position in textarea and you can apply the cursor position getting-setting logics. Somehow try to get the actual click position and force the cursor to stay there.

Community
  • 1
  • 1
Sandeepan Nath
  • 9,966
  • 17
  • 86
  • 144