1

I have a function that I run when the user selects a word in the textarea (typically by double clicking it). It works great on the PC. On android devices, long clicking a word selects it, but doesn't fire onselect.

Is there any way to fix it? Or perhaps some work around to select a word on normal click?

Here's the line in the cshtml

<textarea class="all_txt" id="all_txt" onselect="wordSelected(this, @loggedIn)"></textarea>

And here's the javascript function

function wordSelected(txt, loggedIn) {
    var selected = txt.value.substring(txt.selectionStart, txt.selectionEnd);
    var substring = selected.trim();
    start = selected.search(substring) + txt.selectionStart;
    end = start + substring.length;
    ...
}
Asaf
  • 616
  • 2
  • 6
  • 17
  • You might want to look at [this](http://stackoverflow.com/questions/2952914/copy-text-from-textview-on-android). – Uma Kanth Jul 02 '15 at 09:19
  • What have you tried? I haven't had similar issue but first thing id try would be prevent default at start of your JS function https://developer.mozilla.org/en-US/docs/Web/API/Event/preventDefault.. – ShufflerShark Jul 02 '15 at 09:36
  • Uma, this is completely unrelated the my question – Asaf Jul 02 '15 at 10:17
  • Shark, the function doesn't even run, where would I prevent default? – Asaf Jul 02 '15 at 10:20

1 Answers1

0

Well, I ended up adding a button that calls wordSelected which the user can click after he selected the word. Not optimal, but seems to be the only way.

Asaf
  • 616
  • 2
  • 6
  • 17