get position of cursor in textbox

Posted by Abhi_patil under JavaScript on 2/24/2009 | Views : 12479 | Status : [Member] | Replies : 2
i want to get at what position the cursor is now present. from that i have to get word at that position.




Responses

Posted by: Raja on: 2/24/2009 [Member] Starter

Up
0
Down
See below article for the answer of your question.

http://www.dedestruct.com/2008/03/22/howto-cross-browser-cursor-position-in-textareas/


Thanks

Regards,
Raja, USA

Abhi_patil, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Majith on: 2/24/2009 [Member] Starter

Up
0
Down
Hi Abhi ,

The code supports IE7 compatible version.I am also finding the solution for textarea cursor focus and finally i done it.

<script language="javascript" type="text/javascript"> 


// textEl is the name of TextBox or TextArea
function storeCaret (textEl)
{
if (textEl.createTextRange)
textEl.caretPos = document.selection.createRange().duplicate();
}

function CtypeCursor(objDest)
{
this.dest = objDest;
if (objDest.createTextRange && objDest.caretPos)
{
var caretPos = objDest.caretPos;
if(caretPos.text.charAt(caretPos.text.length - 1) == '')
{
caretPos.text = pt.value;
}
caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
}
}


</script>





Abhi_patil, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response