<!DOCTYPE html>
<html>
<head>
</head>
<body>
<textarea id="mytextarea"></textarea>
<button onclick="alert( getCursorPosition( document.getElementById('mytextarea') ) )">Get Position</button>
<script type="text/javascript">
function getCursorPosition( ctrl ) {
var CaretPos = 0;
if ( document.selection ) {
ctrl.focus ();
var Sel = document.selection.createRange();
Sel.moveStart ('character', -ctrl.value.length);
CaretPos = Sel.text.length;
} else if ( ctrl.selectionStart || ctrl.selectionStart == '0' ) {
CaretPos = ctrl.selectionStart;
}
return CaretPos;
}
</script>
</body>
</html>