highlighting or changing background of some text in input box

Discussion in 'Javascript' started by James Black, Jul 25, 2007.

  1. James Black

    James Black Guest

    Hello,
    I am trying to add an autocomplete functionality for tags, so I want
    to just have the following capability:
    If I type
    ger

    then the word my application matches that to is
    german

    So, I want 'ger' to look normal, and 'man' to be highlighted.

    In an input box I can't use html tags, but I believe there is a
    javascript function that will allow me to highlight just the part I
    want highlighted.

    How would I do this?

    Thanx.
     
    James Black, Jul 25, 2007
    #1
    1. Advertising

  2. James Black

    David Mark Guest

    On Jul 25, 9:55 am, James Black <> wrote:
    > Hello,
    > I am trying to add an autocomplete functionality for tags, so I want
    > to just have the following capability:
    > If I type
    > ger
    >
    > then the word my application matches that to is
    > german
    >
    > So, I want 'ger' to look normal, and 'man' to be highlighted.


    You mean you want "man" to be selected.

    >
    > In an input box I can't use html tags, but I believe there is a
    > javascript function that will allow me to highlight just the part I
    > want highlighted.


    Look into createTextRange for IE and setSelectionRange for others.
    The former creates a range object, which can then be manipulated to do
    what you want. The latter can do it with one call. Make sure you
    detect these methods before calling.
     
    David Mark, Jul 25, 2007
    #2
    1. Advertising

  3. James Black

    James Black Guest

    On Jul 25, 12:56 pm, David Mark <> wrote:

    > > So, I want 'ger' to look normal, and 'man' to be highlighted.

    >
    > You mean you want "man" to be selected.


    I was hoping to be able to arbitrarily change the background for the
    part I want selected, but that appears to not be possible.

    > Look into createTextRange for IE and setSelectionRange for others.
    > The former creates a range object, which can then be manipulated to do
    > what you want. The latter can do it with one call. Make sure you
    > detect these methods before calling.


    Thank you very much.
     
    James Black, Jul 26, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cjl
    Replies:
    1
    Views:
    10,554
    Michael Winter
    Oct 31, 2005
  2. Ed
    Replies:
    1
    Views:
    390
    John Hosking
    May 16, 2007
  3. Aria
    Replies:
    3
    Views:
    108
    Janwillem Borleffs
    Oct 13, 2005
  4. cjl
    Replies:
    7
    Views:
    219
    Thomas 'PointedEars' Lahn
    Oct 30, 2005
  5. Thomas 'PointedEars' Lahn

    Changing text in input text box

    Thomas 'PointedEars' Lahn, Oct 24, 2009, in forum: Javascript
    Replies:
    7
    Views:
    162
    Eric Bednarz
    Oct 26, 2009
Loading...

Share This Page