0

This is a textarea,

<textarea placeholder="what's new..." id="messageID" type="text" ng-model="content"></textarea>

Please how can I trigger insertion point or cursor on this textarea.

sKhan
  • 9,694
  • 16
  • 55
  • 53
Blaze
  • 2,269
  • 11
  • 40
  • 82
  • 1
    what you mean by insertion point? – Nishanth Matha Mar 16 '16 at 09:27
  • Correct, that is a textarea. Can you explain what you mean by *"Trigger insertion point"* Thank you. – NewToJS Mar 16 '16 at 09:28
  • He means the *caret* or *cursor*, as in this question/answer: http://stackoverflow.com/questions/499126/jquery-set-cursor-position-in-text-area [I'm assuming - could just mean *focus*] [update: or even something completely different... who knows] – freedomn-m Mar 16 '16 at 09:29
  • If I click on the textarea I can not insert text. – Blaze Mar 16 '16 at 09:30
  • You don't need `textarea` and `type=text` - but that makes no difference. There's nothing wrong with the code you've provided so must be caused by some other code. You've not provided enough information to reproduce your issue - try your own code in the question in a *new* project/page. Read this [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) – freedomn-m Mar 16 '16 at 09:32

2 Answers2

0
<body OnLoad="document.myform.mytextfield.focus();">
    <form name="myform">
       <textarea name="mytextfield" placeholder="what's new..." id="messageID" type="text" ng-model="content"></textarea>
    </form>
</body>
Natalie Hedström
  • 2,607
  • 3
  • 25
  • 36
Bishoy Bisahi
  • 377
  • 1
  • 11
  • @JnG that is plain javascript, the only difference is it's inline. If you want to run something when the DOM is ready you can replace the `onload` attribute method for `window.onload=function(){//Do something here}` in the script tags. – NewToJS Mar 16 '16 at 09:34
  • please post an answer with this idea – Blaze Mar 16 '16 at 09:35
  • @JnG I would post an answer but I'm not 100% sure what it is you are trying to ask. Also the fact you haven't shown any attempt of fixing the problem yourself, I haven nothing to debug/fix and explain the reason(s) for it not functioning as intended. – NewToJS Mar 16 '16 at 09:40
0
function setSelection(id, start, end) {
    var input = document.getElementById(id);
    input.focus();
    input.setSelectionRange(start, end);
}

with this function you can set the selection begining and end in number of characters from the start of the string (eg. setSelection('messageID', 0, 10) would select the first 10 characters.

If you are using angular you should use other methods to access the DOM input element, bu the setSelectionRange call would be the same.