SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: position cursor

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Apr 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    position cursor

    I was wondering if theres a way to position the cursor to the postition that is 1 past the last character of the textarea. The code below puts the cursor at the last position but i need it to go 1 more space to the right:

    function setCursorAtTheEnd(aTextArea,aEvent) {
    var end = aTextArea.value.length;
    if (aTextArea.setSelectionRange) {
    setTimeout(aTextArea.setSelectionRange,0,[end,end]);
    } else {
    var aRange = aTextArea.createTextRange();
    aRange.collapse(true);
    aRange.moveEnd('character', end);
    aRange.moveStart('character', end);
    aRange.select();
    }
    return false;
    }

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,714
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Danjntn View Post
    I was wondering if theres a way to position the cursor to the postition that is 1 past the last character of the textarea. The code below puts the cursor at the last position but i need it to go 1 more space to the right:
    You'll need to add a space to the end of the text (if one doesn't already exist), to achieve that.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •