Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    moving the cursor position in a text field

    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.

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Cool, anyone know how to do it in IE?

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    624
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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();
    }

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Posts
    624
    Thanks
    0
    Thanked 0 Times in 0 Posts
    To clarify el = document.getElementById('input')


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •