SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I bet this has never been asked...

    write a function that when clicked goes into a textbox and moves the cursor to the end of the text in the box. So if the text box has the word 'apple' in it the cursor is moved to the right of the e in apple.

  2. #2
    "Of" != "Have" bronze trophy Jeff Lange's Avatar
    Join Date
    Jan 2003
    Location
    Calgary, Canada
    Posts
    2,063
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    document.getElementById('textarea').blur();
    document.getElementById('textarea').focus();
    Would that work?
    Who walks the stairs without a care
    It shoots so high in the sky.
    Bounce up and down just like a clown.
    Everyone knows its Slinky.

  3. #3
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no, doesn't that just select the entire text?
    I need the cursor at the end of the word

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried that, Jeff, places cursor at the start.

    Seems like a lot of code, but I don't know another way.
    Code:
    function focusTA( taId )
    {
    	var range = document.getElementById( taId ).createTextRange();
    	range.expand( 'textedit' );
    	range.collapse( false );
    	range.select();
    }
    Of course, this is IE-only. You'd have to look into the DOM2 Range Interface for Mozilla and Opera, methinks.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    runat="server" Golgotha's Avatar
    Join Date
    Nov 2001
    Location
    Colorado
    Posts
    2,085
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    help me out beetle, onClick of the button I want it to go into the text box and have the cursor to the right of the text. What did I do wrong?

    Code:
     
     
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript">
    function focusTA( taId )
    {
     var range = document.getElementById( taId ).createTextRange();
     range.expand( 'textedit' );
     range.collapse( false );
     range.select();
    }
    </script>
    </head>
    <body>
    <input name="taId" type="text" value="apple" id="taId">
    <input type="button" name="button" value="button" onClick="focusTA(taId)">
    </body>
    </html>

  6. #6
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You didn't sent the ID as a string!

    <input name="taId" type="text" value="apple" id="taId">
    <input type="button" name="button" value="button" onClick="focusTA('taId')">

    It's the ID of the textarea that you send in to the function.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





Bookmarks

Posting Permissions

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