View Full Version : Cursor Location within form elements
is it possible to detect which form element the cursor is currently in, and where in that element it is?
DarkStreetDev
05-02-2003, 11:45 PM
Originally posted by tEE
is it possible to detect which form element the cursor is currently in, and where in that element it is?
As far as I know, you can't know where in the element the cursor is in. As to your fisrt question: MAYBE you can use the focus() to see where it is...
Maybe you should rather tell us what you want to do, maybe we can find a better or easier sollution.
Jon Hanlon
05-03-2003, 10:30 PM
It's not easy.
Microsoft have a way of finding the caret at http://msdn.microsoft.com/library/en-us/dnwebteam/html/webteam12032001.asp?frame=true
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JScript">
function saveCaret(elem)
{
if ( elem.isTextEdit )
elem.caretPos = document.selection.createRange();
}
function getCaretPos(elem)
{
if ( elem.isTextEdit && elem.caretPos )
{
var bookmark = "~";
var orig = elem.value;
var caretPos = elem.caretPos;
caretPos.text = bookmark;
var i = elem.value.search( bookmark );
window.status = "Caret is at character " + i;
elem.value = orig;
}
}
</SCRIPT>
</HEAD>
<BODY>
<INPUT NAME="txtInput" ONSELECT="saveCaret(this)"
ONCLICK="saveCaret(this)" ONKEYUP="saveCaret(this)" VALUE="Where are you?">
<INPUT TYPE="button" VALUE="caret pos" ONCLICK="getCaretPos(txtInput)">
</BODY>
</HTML>
I'm building a content management system for my company and don't want the user to have to type <br> to make line breaks
That script did it, thanks for that :)
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.