Set cursor to specific position on specific line in a textarea

I’ve updated your fiddle see: http://jsfiddle.net/eghpf/2/ I’ve added var currentPosition which is used in this method function setSelectionRange(input, selectionStart, selectionEnd) { if (input.setSelectionRange) { input.focus(); input.setSelectionRange(selectionStart, selectionEnd); } else if (input.createTextRange) { var range = input.createTextRange(); range.collapse(true); range.moveEnd(‘character’, selectionEnd); range.moveStart(‘character’, selectionStart); range.select(); } } Which comes from this jQuery Set Cursor Position in Text Area … Read more

Get current cursor position in a textbox

It looks OK apart from the space in your ID attribute, which is not valid, and the fact that you’re replacing the value of your input before checking the selection. function textbox() { var ctl = document.getElementById(‘Javascript_example’); var startPos = ctl.selectionStart; var endPos = ctl.selectionEnd; alert(startPos + “, ” + endPos); } <input id=”Javascript_example” name=”one” … Read more

How to get the cursor position in bash?

You have to resort to dirty tricks: #!/bin/bash # based on a script from http://invisible-island.net/xterm/xterm.faq.html exec < /dev/tty oldstty=$(stty -g) stty raw -echo min 0 # on my system, the following line can be replaced by the line below it echo -en “\033[6n” > /dev/tty # tput u7 > /dev/tty # when TERM=xterm (and relatives) … Read more