Inserting characters at current cursor point in textarea

Discussion in 'Javascript' started by M Wells, Dec 11, 2003.

  1. M Wells

    M Wells Guest

    Hi All,

    I've been checking the online javascript libraries for code that will
    show me how to insert characters at the current cursor point in a
    textarea form field to help me markup content I write for my site.

    Unfortunately, all I've been able to locate are plugin applets that
    give wysiwig functionality, which is not what I'm looking for.

    So I'm wondering if someone can provide some code, or point me to some
    code, that will respond to a click on a button by inserting, as an
    example, the following text at the current cursor position:
    "<strong></strong>".

    Ideally, what I'd like to do is if text is highlighted, then put
    "<strong>" on one side, and "</strong>" on the other, and if no text
    is highlighted, then simply insert "<strong></strong>" at the current
    position and re-position the cursor so that it is between the
    characters "><" so I can start typing straight away.

    Any help with this would be immensely appreciated!

    Much warmth,

    Murray
    http://www.planetthoughtful.org
    Building a thoughtful planet,
    One quirky comment at a time.
     
    M Wells, Dec 11, 2003
    #1
    1. Advertisements

  2. Martin Honnen, Dec 11, 2003
    #2
    1. Advertisements

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. =?Utf-8?B?VG9tYXMgS2VwaWM=?=

    Changing DEFAULT cursor to WAIT cursor in ASP

    =?Utf-8?B?VG9tYXMgS2VwaWM=?=, Apr 5, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,539
    Bruce Barker
    Apr 5, 2005
  2. Peer W Hansen
    Replies:
    0
    Views:
    6,807
    Peer W Hansen
    May 16, 2004
  3. invy
    Replies:
    4
    Views:
    631
    CBFalconer
    Dec 28, 2006
  4. dmaziuk
    Replies:
    3
    Views:
    930
    Chris Gonnerman
    Jan 25, 2011
  5. Saraswati lakki
    Replies:
    0
    Views:
    1,667
    Saraswati lakki
    Jan 6, 2012
  6. Geoff Soper

    Positioning the cursor in a textarea

    Geoff Soper, Feb 19, 2005, in forum: Javascript
    Replies:
    1
    Views:
    143
    Martin Honnen
    Feb 19, 2005
  7. cyber0ne
    Replies:
    0
    Views:
    212
    cyber0ne
    Apr 29, 2005
  8. Frank Peterson
    Replies:
    0
    Views:
    177
    Frank Peterson
    Feb 21, 2008
Loading...