Controlling the cursor position when the page is loading by a keyword

I have a web page at http://dot.kr/x-test/html/loading_focus.php?caret=51

if you click the link above, your cursor is on just before "8"th line because 51st position is on 8th line in the string inside the textArea.

I like to make it like the following.

if you click the link http://dot.kr/x-test/html/loading_focus.php?caret=51, your cursor is on the just before the text “51” which is on 51st line in the textArea.

if you click the link http://dot.kr/x-test/html/loading_focus.php?caret=ten, your cursor is on the just before the text “ten” which is on 10th line in the textArea.

if you click the link http://dot.kr/x-test/html/loading_focus.php?caret=sixteen, your cursor is on the just before the text “sixteen” which is on 16th line in the textArea.

Thanks in advance

Hi there joon1,

the “textarea element” puts text on one line, so
what you are asking is not possible - (A,F.A.I.K). :ng:

Perhaps this alternative may suit your requirements…

[code]

untitled document #longlist { width:50%; height:200px; margin:auto; border:1px solid #999; overflow:auto; } #longlist input { display:inline-block; box-sizing:border-box; width:100%; margin:0; border:0; font-size:100%; } .bgcolor { background-color:#ddd; }

[/code]

coothead

[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.

if you click the link http://dot.kr/x-test/html/loading_focus.php?caret=t, your cursor is on the just before the text “two” which is on 2nd line in the textArea.

if you click the link http://dot.kr/x-test/html/loading_focus.php?caret=s, your cursor is on the just before the text “six” which is on 6th line in the textArea.

Can I make it with your help?

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. :ok:

coothead

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.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.