SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2004
    Location
    london
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Check the script - cant get the location of a textarea cursor

    Here is the script, what i am trying to do is to read the location of the cursor in a textbox and put the text in the current cursor location. Dont work at all,
    textEl.caretPos returns null all the time...(textEl is a textarea element)

    Any ideas why is not working ??

    thanks in advance

    function insertAtCaret(textEl,text)
    {
    if (textEl.createTextRange && textEl.caretPos)
    {
    var caretPos = textEl.caretPos;
    caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
    }
    else
    {
    textEl.value = textEl.value + " " + text;
    }
    }
    Last edited by mkermit; Dec 1, 2004 at 06:00. Reason: title had textbox instead of textarea

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


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
  •