...

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



misterx
02-22-2003, 11:29 PM
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.

jkd
02-22-2003, 11:51 PM
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.

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

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

function Show_End_Of_Path(el) {
tr = el.createTextRange()
tr.collapse(false)
tr.select();
}

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum