I need to find the current position of the cursor so I can store it in a variable. I've looked at a few SO answers and none have been successful.
What I have so far:
function getCaretPos(id) {
var el = Ext.getCmp(id);
var rng, ii=-1;
var currSelection = window.getSelection();
if(currSelection){
currSelection.modify("character", el.value.length);
// get the current position
// ii = currentPosition
}
return ii;
};
For example: I have a textfield displaying data.
MYWORD
When I place the cursor between the Y and W it should return 2. I've seen a few examples for older versions of IE but none seem to work for me in Chrome.
Does anyone know how this can be done?