arash wrote:
Hi!
I am trying to write some ajax based IDE.
I just cant get a div to open where the cursor in the textarea is
blinking (in order to suggest possibilities.. )
Is there a way to get the exact position (pixel-top, pixel-left) of the
cursor of a text area??
greetings, arash
Hi
It is certainly possible in Internet Explorer, but I AFAIK not for
others.
In Internet Explorer you could try something like this (very rough for
illustration only, and bit buggy with the Enter, Delete and Arrow
keys):-
<HTML>
<HEAD>
<SCRIPT>
function fKey()
{
var r=document.sele ction.createRan ge();
var tRect=r.getBoun dingClientRect( );
var TOP=tRect.top;
var LEFT=tRect.left ;
positionInfo.in nerText=TOP+":" +LEFT;
myDiv.style.dis play="block";
myDiv.style.top =TOP;
myDiv.style.lef t=LEFT+7;
}
</SCRIPT>
</HEAD>
<TEXTAREA onkeydown=fKey( ) style="WIDTH: 100%; HEIGHT: 300px">
</TEXTAREA>
<P id=positionInfo ></P>
<DIV id=myDiv style="border:1 px solid red; z-index:10; left:0; top:0;
position: absolute; background-color: yellow; padding:2px;
display:none;"> Suggested text</DIV>
</BODY>
</HTML>
Regards
Julian Turner