open a div where cursor blinks in textarea

A

arash

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
 
J

Julian Turner

arash said:
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.selection.createRange();
var tRect=r.getBoundingClientRect();

var TOP=tRect.top;
var LEFT=tRect.left;

positionInfo.innerText=TOP+":"+LEFT;

myDiv.style.display="block";
myDiv.style.top=TOP;
myDiv.style.left=LEFT+7;
}

</SCRIPT>

</HEAD>
<TEXTAREA onkeydown=fKey() style="WIDTH: 100%; HEIGHT: 300px">
</TEXTAREA>
<P id=positionInfo></P>
<DIV id=myDiv style="border:1px 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top