I have a page at

The page need a parameter “caret”

if you click the link, your cursor inside textarea will be blink between “9” and “0”.

if you click the link, your cursor inside textarea will be blink between “0” and “a”.

if you click the link, your cursor inside textarea will be blink between “a” and “b”.

Let’s suppose I cannot use the parameter “caret” but, instead, oldCaret.
But the parameter “oldCaret” doesn’t work at

So I made the code below at the page using PHP

if (isset($_GET['newCaret']) ) {
$location='?caret=' .$_GET['newCaret'];

With the code above newCaret do work at by redirection to caret from newCaret.

I want the correct cursor position without redirection.

The trial code of PHP below doesn’t work.


Can I use newCaret without redirection by your help?

Hi @joon1, with your JS code

   var url=location.href;
   var no=url.substring(url.lastIndexOf("caret=")+6);

your not checking for the exact caret parameter anyway but just for any parameter that ends with caret. So you might simply convert the query string to lower case first in order to also match oldCaret and newCaret:

var params =
var no = params.substring(url.lastIndexOf('caret=') + 6)
setCaretPosition(document.getElementById('get'), no)

I made another page with your code at

any of,, and seems not to work for cursor positioning.

Ah sry, yes I renamed the url variable to params but did not properly replace it everywhere… BTW you can see such errors in the console of the browser dev tools, which makes them easy enough to fix.

I removed “var no=url.substring(url.lastIndexOf(“caret=”)+6)”; at

It seems not to work.

But why? You’d just have to replace the remaining url reference with params which I had forgot (or the other way round).

Of course not, now no is not defined… did you try checking the console?

At, it says like the following

I don’t know how to fix it.

As I said, my mistake – just replace url with params (or the other way round).

Do you mean change url to param?
I change like the followng at

it seems not to work.

No to params.

I might have to give up this time.

Really? You just need to change param to params and you’re giving up before trying that one simple thing?

1 Like
I did.
Thank you, Paul_Wilkins and m3g4p0p


By the way, What is the literal meaning of caret?
Character set or something?

A caret is just an upside down V character, the ^ symbol that is sometimes used below a line of text to mark a position.

For example:

The third word is marked with a caret.