I need a code to find current position of cursor in a textbox/textarea. It should work with chrome and firefox. Following is the code which I am using:
<!DOCTYPE html>
<html>
<head>
<script>
function textbox()
{
document.getElementById('Javascript_example').value = document.activeElement.id;
var ctl = document.getElementById('Javascript_example');
alert(ctl);
var startPos = ctl.selectionStart;
alert(startPos);
var endPos = ctl.selectionEnd;
alert(endPos);
}
</script>
</head>
<body>
<input id="Javascript_example" name="one" type="text" value="Javascript_example" onclick="textbox()">
</body>
</html>
Any suggestion?