SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    N. CA
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Moving the cursor position within a textarea

    Im trying to set focus on a textarea that already has some text in it. Im using the following code in my body tag:

    <body onload="document.getElementById('replybox').focus();">

    It works but in Firefox, the cursor position appears at the end of the existing content of the textarea. How would I make it so the cursor shows up at the beginning of the content rather than at the end?

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    N. CA
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey thanks. Actually I found a solution before I got your response. It's a bit verbose but it could be slimmed down fairly easily. I tested it in IE 6 and FireFox (newest version).

    <body onload="(document.all)?document.getElementById('replybox').focus():document.getElementById('replybox').setSelectionRange(0,0);document.getElementById('replybox').focus()">


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
  •