joon1
April 4, 2020, 6:35am
1
I have a page at http://form.kr/dest/caret.php
The page need a parameter “caret”
if you click the link http://form.kr/dest/caret.php?caret=9 , your cursor inside textarea will be blink between “9” and “0”.
if you click the link http://form.kr/dest/caret.php?caret=10 , your cursor inside textarea will be blink between “0” and “a”.
if you click the link http://form.kr/dest/caret.php?caret=11 , 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 http://form.kr/dest/caret.php?oldCaret=10
So I made the code below at the page using PHP
if (isset($_GET['newCaret']) ) {
$location='?caret=' .$_GET['newCaret'];
header("location:$location");exit();
With the code above newCaret do work at http://form.kr/dest/caret.php?newCaret=10 by redirection to caret from newCaret.
I want the correct cursor position without redirection.
The trial code of PHP below doesn’t work.
$_GET['caret']=$_GET['oldCaret'];
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);
setCaretPosition(document.getElementById("get"),no);
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 = window.location.search.toLowerCase()
var no = params.substring(url.lastIndexOf('caret=') + 6)
setCaretPosition(document.getElementById('get'), no)
joon1
April 4, 2020, 10:40am
3
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.
joon1
April 4, 2020, 12:25pm
5
I removed “var no=url.substring(url.lastIndexOf(“caret=”)+6)”; at http://form.kr/dest/caret3.php?oldCaret=10
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).
joon1:
It seems not to work.
Of course not, now no
is not defined… did you try checking the console?
joon1
April 4, 2020, 1:07pm
7
At http://form.kr/dest/caret2.php , 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).
joon1
April 4, 2020, 4:26pm
9
Do you mean change url to param?
I change like the followng at http://form.kr/dest/caret5.php?caret=10
it seems not to work.
joon1
April 5, 2020, 12:44am
11
m3g4p0p:
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
joon1
April 5, 2020, 6:38am
13
http://form.kr/dest/caret6.php?oldcaret=10
I did.
Thank you, Paul_Wilkins and m3g4p0p
2 Likes
joon1
April 5, 2020, 7:08am
14
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.
^
system
Closed
July 5, 2020, 5:04pm
16
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.