[quote]the “textarea element” puts text on one line, so
what you are asking is not possible - (A,F.A.I.K).[/quote]
I am afraid but I don’t quite understand what you mean by the above.
if your suggestion “textarea element” puts text on one line in the above quote means the parameter value of caret should be one word, I like to make it like the following.
Perhaps a simple example will help you understand that however
you arrange the contents of a the “textarea element”, those contents
remain as a single line of text.
[code]
untitled document
Arrange the contents of the textarea to suit your requirements
1st line 2 3 4 5 6 7 8 9 10
test textarea
[/code]
Your javascript sets the caret at selected points in a single line of text.
It cannot go to [b] imaginary lines[/b] of your making. :ng:
That is the reason for the alternative method that I gave you.
A textarea can contain only Character Data. i.e. a String
The character data can include newlines / carriage returns i.e. \r, \n, \r\n dependening on the OS
Browsers do not display these characters as lines unless they are inside pre tags or converted to br tags (well, in some cases p tags - ugh)
Th only way I can think of to determine which “line” a word occurs in is to split the string into pieces and look for the word in each or find the word and then find the first “line character” that precedes it.