Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Get selected text from textArea

Hi,

Anyone knows how to get the selected text from textArea?

I found the "selected" event from textArea, but how to use it? and is this usefull?

— asked April 20th 2010 by Marcos Gonçalves
  • iphone
  • textarea
  • tip
0 Comments

7 Answers

  • Accepted Answer

    This is straight from the docs… pretty self explanatory… (use the range property in the event object)

    selected
    fired when the text in the field is selected
    Event properties

    range
    the range of text. range is an object with the properties "location" and "length".
    source the source object that fired the event
    type the name of the event fired

    — answered April 20th 2010 by Raul Riera
    permalink
    0 Comments
  • Do you mean 'selected' as in when a user uses the copy/paste select functions with an iphone? (with those draggable 'bars')

    If so, no idea.

    Or do you mean when the textarea has 'focus'?

    — answered April 20th 2010 by Kosso
    permalink
    0 Comments
  • Kosso

    Yeah! like select words to copy/paste!

    I need to get the selected word and save on database.
    I think theres no difficulty to do this, but i dont know how :D

    — answered April 20th 2010 by Marcos Gonçalves
    permalink
    0 Comments
  • Thanks all for the help given

    I dont know how I've not did it before, but now is done!
    I used this simple code: txtTeste.value.substr(e.range.location, e.range.length);

    — answered April 20th 2010 by Marcos Gonçalves
    permalink
    0 Comments
  • Hi guys, how to use selected event in textarea , i want to get selected text from textarea can you pls tell the sample example for this one….

    — answered January 6th 2012 by saravanan P
    permalink
    0 Comments
  • Hello altogether,

    i work with SDK 1.8.2 and simulator with iOS5. I will use the listener "selected" at a textarea. Source:

    txtAction.addEventListener('selected', function(e)
    {
        Ti.API.info("Hello");
    });
    

    After a selection a crash comes:

    [ERROR] application raised an exception. -[TiRange boundBridge:withKrollObject:]: unrecognized selector sent to instance 0xaea8b60
    

    I will get a selection for detect the cursorposition. Is there a better way for do this? Thanks

    — answered March 1st 2012 by Walter Zeidler
    permalink
    0 Comments
  • This Bug is fixed.

    — answered April 10th 2012 by Walter Zeidler
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.