B
Barry
Retoring Caret Position after text field correction
--------------------------------------------------------------------------------
Hi, my code has the following form -
function ConvertOld(myfield)
{
if (myfield.inchange)
return;
myfield.inchange=true;
myfield.value = myfield.value.replace(/A\//g,"Á");
myfield.value = myfield.value.replace(/a\//g,"á");
myfield.value = myfield.value.replace(/E\//g,"É");
myfield.value = myfield.value.replace(/e\//g,"é");
myfield.value = myfield.value.replace(/I\//g,"Í");
myfield.value = myfield.value.replace(/i\//g,"í");
myfield.value = myfield.value.replace(/O\//g,"Ó");
myfield.value = myfield.value.replace(/o\//g,"ó");
myfield.value = myfield.value.replace(/U\//g,"Ú");
myfield.value = myfield.value.replace(/u\//g,"ú");
myfield.value = myfield.value.replace(/e\//g,"é");
myfield.inchange=false;
}
<form action="">
<input type="text" size="20" maxlength="50" name="myinput"
onKeyUp="ConvertOld(this)"/>
The problem is that the caret is forced to the end, when ever a key
such as the back button is pressed, and the user cant correct a
mistake within the textbox by moving back to it.
One change I made was -
var myStr = "";
function ConvertOld(myfield)
{
if(myfield.value == myStr)
return;
myStr = myfield.value;
But this isn't ideal. The user can now more the caret within the text
field, but once they change something, like deleting a letter the'd
like to change, the caret is forced to the end again.
For example -
User enters -
Intarnet
then realizes their mistake and moves cursor to position three in
order to delete the "a" and change it to an "e", doing so gives -
Intrnet
but the cursor is moved to the end, and the user has to move back to
position 3 in order to enter the "e" -
Any solutions?
Cheers,
Barry.
--------------------------------------------------------------------------------
Hi, my code has the following form -
function ConvertOld(myfield)
{
if (myfield.inchange)
return;
myfield.inchange=true;
myfield.value = myfield.value.replace(/A\//g,"Á");
myfield.value = myfield.value.replace(/a\//g,"á");
myfield.value = myfield.value.replace(/E\//g,"É");
myfield.value = myfield.value.replace(/e\//g,"é");
myfield.value = myfield.value.replace(/I\//g,"Í");
myfield.value = myfield.value.replace(/i\//g,"í");
myfield.value = myfield.value.replace(/O\//g,"Ó");
myfield.value = myfield.value.replace(/o\//g,"ó");
myfield.value = myfield.value.replace(/U\//g,"Ú");
myfield.value = myfield.value.replace(/u\//g,"ú");
myfield.value = myfield.value.replace(/e\//g,"é");
myfield.inchange=false;
}
<form action="">
<input type="text" size="20" maxlength="50" name="myinput"
onKeyUp="ConvertOld(this)"/>
The problem is that the caret is forced to the end, when ever a key
such as the back button is pressed, and the user cant correct a
mistake within the textbox by moving back to it.
One change I made was -
var myStr = "";
function ConvertOld(myfield)
{
if(myfield.value == myStr)
return;
myStr = myfield.value;
But this isn't ideal. The user can now more the caret within the text
field, but once they change something, like deleting a letter the'd
like to change, the caret is forced to the end again.
For example -
User enters -
Intarnet
then realizes their mistake and moves cursor to position three in
order to delete the "a" and change it to an "e", doing so gives -
Intrnet
but the cursor is moved to the end, and the user has to move back to
position 3 in order to enter the "e" -
Any solutions?
Cheers,
Barry.