Hi @joon1, if you open the console of your browser dev tools you’ll see an
… because you’re trying to use a number as parameter name, which should probably be passed as an argument instead; furthermore, you’re not actually calling FocusMe() at any point. And if you were, you’d get a type error because you misspelled getElemenById() in line 34, and then a reference error because you forgot to copy / paste the setSelRange() function from that SO thread. After fixing those issues it should work as expected.
That would be syntactically correct, but you’re still confusing the function parameter (in this case, a variable with the name anotherName) with the arguments you want to pass to the function (such as the string "anotherName" or the number 12); also you’re still not calling the function. Consider:
function foo (bar) {
console.log('You passed the value', bar)
}
foo('someText') // -> You passed the value someText
foo(12) // -> You passed the value 12
So your function call would have to be focusMe('anotherName')… see here for a general introduction to functions in JS:
(BTW function names should start lower cased if they are not a constructor functions).
I am sorry it is a good code for my purpose because my cursor can be easily located at line 12 of http://form.kr/test01/textarea/cursorBlock.php as I move the cursor slightly toward right with right arrow. key.
Thank you for the code.
I think you got something mixed up here; setSelectionRange() takes the start and end position as the first and second argument, respectively – not the textarea on which you’re already calling the method.
If you want to place the caret at line number 12, I wouldn’t search for the string "12" at all; instead, you might split() the text by line feeds, and get the length of the string from join()ing the first n substrings: