473,471 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Moving the cursor (insertion point) in an input (text) field

Hello all,

When one tabs through a form (specifically, in Firefox), all the text in
a field is automatically selected.

What I'm looking for is a way to put a function (in onFocus perhaps)
that will automatically move to the END of the existing text (a blinking
cursor).

Yes, I've Googled, but cannot seem to locate just what I'm looking for.
I'm not a newbie when it comes to programming, but my forte is Python
and PHP, not Javascript.

Thanks,
Klaus
Jun 27 '08 #1
3 4573
On May 28, 2:57 pm, Klaus Brune <klaus.brune-RemoveT...@gmail.com>
wrote:
Hello all,

When one tabs through a form (specifically, in Firefox), all the text in
a field is automatically selected.

What I'm looking for is a way to put a function (in onFocus perhaps)
that will automatically move to the END of the existing text (a blinking
cursor).

Yes, I've Googled, but cannot seem to locate just what I'm looking for.
I'm not a newbie when it comes to programming, but my forte is Python
and PHP, not Javascript.

Thanks,
Klaus
Klaus,

just an idea, maybe a bit naive: send to client a LEFT ARROW command
after the select method, which will make the cursor to point at the
end of selection.

Thiago
Jun 27 '08 #2
On May 28, 4:56*pm, Thiago Macedo <thiago.ch...@gmail.comwrote:
On May 28, 2:57 pm, Klaus Brune <klaus.brune-RemoveT...@gmail.com>
wrote:
Hello all,
When one tabs through a form (specifically, in Firefox), all the text in
* a field is automatically selected.
What I'm looking for is a way to put a function (in onFocus perhaps)
that will automatically move to the END of the existing text (a blinking
cursor).
Yes, I've Googled, but cannot seem to locate just what I'm looking for.
I'm not a newbie when it comes to programming, but my forte is Python
and PHP, not Javascript.
Thanks,
Klaus

Klaus,

just an idea, maybe a bit naive: send to client a LEFT ARROW command
after the select method, which will make the cursor to point at the
end of selection.

Thiago
You may try use selection ranges, something like the following:

function setCaretToEnd(ctrl) {
if(ctrl.setSelectionRange) {
ctrl.setSelectionRange(ctrl.value.length, ctrl.value.length);
}
else if (ctrl.createTextRange) {
var range = ctrl.createTextRange();
range.moveStart('character', ctrl.value.length);
range.select();
}
}

Then you can call this onfocus: <input id="test" type="text"
onfocus="setCaretToEnd(this);"/>

HTH

Jun 27 '08 #3
Tom Cole wrote:
On May 28, 4:56 pm, Thiago Macedo <thiago.ch...@gmail.comwrote:
>On May 28, 2:57 pm, Klaus Brune <klaus.brune-RemoveT...@gmail.com>
wrote:
>>Hello all,
When one tabs through a form (specifically, in Firefox), all the text in
a field is automatically selected.
What I'm looking for is a way to put a function (in onFocus perhaps)
that will automatically move to the END of the existing text (a blinking
cursor).
Yes, I've Googled, but cannot seem to locate just what I'm looking for.
I'm not a newbie when it comes to programming, but my forte is Python
and PHP, not Javascript.
Thanks,
Klaus
Klaus,

just an idea, maybe a bit naive: send to client a LEFT ARROW command
after the select method, which will make the cursor to point at the
end of selection.

Thiago

You may try use selection ranges, something like the following:

function setCaretToEnd(ctrl) {
if(ctrl.setSelectionRange) {
ctrl.setSelectionRange(ctrl.value.length, ctrl.value.length);
}
else if (ctrl.createTextRange) {
var range = ctrl.createTextRange();
range.moveStart('character', ctrl.value.length);
range.select();
}
}

Then you can call this onfocus: <input id="test" type="text"
onfocus="setCaretToEnd(this);"/>

HTH
Thanks, Thiago

This works -- but only sort of... it works when I enter the field via a
mouse click, but not when tabbing into the field (all the data is still
selected). Any ideas?

Note: this is a company-specific application using Firefox 2.0.0.14
exclusively, so compatibility with other browsers is not an issue.

Note 2: this may seem like a small issue, but it becomes more magnified
when you consider that this form is being used by touch-typists (no
mouse) to enter literally tens of thousands of items per day. So having
to constantly move the cursor to the end of the text to modify the last
one or two characters (in this case, numbers) is becoming a major nuisance.

The full story: The form has two text boxes to contain numbers, a
starting and ending sequence. The idea is that the data entry person
will enter the starting sequence, and when they tab to the next field,
the ending sequence, it will automatically (1) copy the starting
sequence because the numbers are similar, to save typing (which the form
now does in an onBlur event in the starting sequence), and (2) move the
cursor to the end of the field so that all the typist has to do is
backspace once or twice to change the last few digits of the ending
sequence.

The problem I'm having is with the implementation of part 2 above.
Simulating a right-arrow key press upon entry into the field seems like
it should work, but I have not been able to get that working either.

- Klaus
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Kevin Blount | last post by:
I'm playing with dragable <DIV>s, being inspired by google.com/ig, where you can move items on the page around and have items you move over change position if necessary. I have 3 div's setup,...
3
by: (Pete Cresswell) | last post by:
I've got this DoCmd in a fields Change() event so that as the user types, the underlying table (also visible in another screen...) will be updated in realtime - instead of waiting for the screen TB...
2
by: anonymous | last post by:
is there a way to surpress the insertion cursor in a rich text box? for instance, i might want a RichTextBox to display some text as a Label would-- readonly, no insertion cursor though text...
2
by: DaveR | last post by:
Can anybody help me to a)get the user's cursor insertion point (caret) from a multiline textbox, using client-side script I suppose, and then b)return the position to VB code behind? I have...
4
by: Woody Splawn | last post by:
I have a grid with, lets say, 3 fields in it, Debit, Credit and Comments, in that order. When the user moves to the debit field, if he enters data in it, I would like for the cursor to skip past...
7
by: jcrouse | last post by:
I use the following three subs to click on a label and reposition it at runtime: Private Sub lblP1JoyUp_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)...
0
by: Mehina | last post by:
i am having a problem regarding the disappearance of the cursor in the DataGrid cell after i change the width of the column on runtime.here is a function which is being called in the Textchanged...
2
by: Jassim Rahma | last post by:
how can i change the cursor of the textbox to the block style?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.