0

JS

function doGetCaretPosition (ctrl)
{
    var CaretPos = 0;
    // IE Support
    if (document.selection)
    {
        ctrl.focus ();
        var Sel = document.selection.createRange ();
        Sel.moveStart ('character', -ctrl.value.length);
        CaretPos = Sel.text.length;
    }
    // Firefox support
    else if (ctrl.selectionStart || ctrl.selectionStart == '0')
    {
        CaretPos = ctrl.selectionStart;
    }
    return (CaretPos);
}

window.onload=function(){       
    editor = CKEDITOR.replace('content');
}

HTML:

<body>
    <form name="inForm" method="post">

        <textarea id="content" name="content" cols="100%" rows="10">1234dfgdf5</textarea>
        <br>
        <input type="button" onclick="alert(doGetCaretPosition(document.getElementById('content')));"
            value="Get Position">
    </form>
</body>

Why "Get Position" and click it to continue zeros is coming?

Tom Fenech
  • 72,334
  • 12
  • 107
  • 141
  • `.focus()` will focus to input to text starting position. Working fine!! http://jsfiddle.net/kunknown/fZQY3/ – Kiran Mar 22 '14 at 10:32
  • The problem is you're using [CKEditor Web Text Editor](http://ckeditor.com/) so what you think is your textarea is in reality an ` – user692942 Mar 22 '14 at 10:38
  • possible duplicate of [Set cursor to specific position in CKEditor](http://stackoverflow.com/questions/16835365/set-cursor-to-specific-position-in-ckeditor) – user692942 Mar 22 '14 at 10:43
  • Also found this [SO answer](http://stackoverflow.com/a/16859577/692942) which looks promising, you might find it useful to search SO in future before posting. – user692942 Mar 22 '14 at 10:44

0 Answers0