View Full Version : moving the cursor position in a text field

02-23-2003, 12:29 AM
Is there a function or method or something to move the position of the cursor in a text field to the end of whatever text might be in there?

I have a form field that I want someone to enter a URL into. I wrote a function that inserts http:// into the field when you click on it but it puts the cursor BEFORE that text which kinda defeats the purpose of putting it in there in the first place. Thanks for any tips.

02-23-2003, 12:51 AM
In Gecko (NS6+, Mozilla, Galeon, Chimera, etc) it would be as easy as

textBox.setSelectionRange(textBox.value.length, textBox.value.length);

Where textBox is a reference to the input element...

IE would require some nasty TextRange stuff I think.

02-23-2003, 01:50 AM
Cool, anyone know how to do it in IE?

Graeme Hackston
02-23-2003, 06:03 AM
Enough code in IE to make it worth using a function

function Show_End_Of_Path(el) {
tr = el.createTextRange()

Graeme Hackston
02-23-2003, 06:15 AM
To clarify el = document.getElementById('input')