SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Sep 2001
    Location
    UK
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting position of cursor inside a text input

    I'm implementing an autocomplete textbox on a site using the script at http://codeproject.com/jscript/jsactb.asp. As you can see from the example on that page, the drop-down list remains at the start of the input when you enter more than one term. Is there any way to keep it moving along the input so that it stays in line with each delimiter entered? All the position data I can find relates to the mouse cursor, not the typing cursor, so I can't find a way to assign the correct offset to the drop-down list.

    If this isn't possible, is there another script that does this in a more intuitive way?

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I think that you can access the cursor position through the selectionStart property.

    Code:
    var cpos = document.getElementById('your-input').selectionStart;
    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Member
    Join Date
    Sep 2001
    Location
    UK
    Posts
    24
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Eric, that seems to work. However, it returns the number of characters into the text input, and for CSS positioning the drop-down I need a pixel value (I think). Is there any way to get this, given that the font isn't fixed-width?

  4. #4
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I don't know of any way to accomplish that, but that does not mean that there isn't one.

    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.


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
  •