Get selected text from text area...

0 favourites
  • 3 posts
From the Asset Store
Change delay, create new lines, "backspace" the text
  • Hi all,

    ¿Can you help me with this?

    I'm trying to get the selected text from a text area using javascript.

    It does not work because "selectionStart" and "selectionEnd" seem to be undefined.

    This is my code:

    const instance = runtime.objects.textAreaObject.getFirstInstance();

    var startSel= instance.selectionStart;

    var endSel= instance.selectionEnd;

    var result = instance.text;

    result = result.substr(startSel, endSel - startSel);

    alert(result);

    Any idea of what is happening?

    Do you know any other way to achieve it?

    Thank you

  • Maybe I'm wrong but isn't all what you need getSelection() or window.getSelection().toString();?

    So alert(getSelection()); should give you the selected text?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Great!!

    Thanks a lot!

    It woks with :

    window.getSelection().toString();

    But I had to uncheck the "use worker" option in project settings so I can access window object

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)