You must Sign In to post a response.
  • Category: ASP.NET

    How to get cursor position in java script?

    How to get cursor position in textarea/textbox by using javascript?

    I already used document.selection.createrange().I am using IE11.It is throwing an error when I am putting break point.It says 'Undefined'.I already used document.getSelection().I will apreciate if anybody provide me entire code along with explaination
  • #757034

    Hi Pinky,

    kindly try the below code for ur ref:

    <asp:Textbox id="txtid" text="Javascript example" onclick="textbox()"></asp:TextBox>


    function textbox()
    var ctl = document.getElementById('txtid');
    var startPos = ctl.selectionStart;
    var endPos = ctl.selectionEnd;
    alert(startPos + ", " + endPos);

    Hope it will work for uu


  • #757035
    Hi Pinky,

    As ur ur suggestion u can use this below code also..

    var position = window.getSelection().getRangeAt(0).startOffset;


  • #757036
    Undefined and undefined get added into alert box.

  • #757629
    Thanks chitaranjan mallick ,it worked for me.

  • Sign In to post your comments