Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


how do I specify cursor position in a textarea?

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,196
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> how do I specify cursor position in a textarea?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 how do I specify cursor position in a textarea? - 6/21/2001 6:27:48 AM   
  peach24

 

Posts: 7
Score: 0
Joined: 6/9/2001
From: USA
Status: offline
I have a problem. Here is where the problem is

-----SAMPLE CODE------------



I have made an online html editor
Where i click a button and a html tag would apear in the textarea.

the problem is that i want to place the tag where i place the cursor. It
is at the moment placing the text always at the end of the string.

How do i specify that it must paste the text where i place the cursor
and give the textarea focus.

Please help me
 
 
Post #: 1
 
 Re: how do I specify cursor position in a textarea? - 6/21/2001 6:29:41 AM   
  gold7

 

Posts: 10
Score: 0
Joined: 6/9/2001
From: USA
Status: offline
Ahh.. You definitely have a problem. HTML text objects don't have text
selection properties like VB text objects.

I can think of two workarounds, both of them ugly.

The first involves DHTML. You could capture the onMouseDown event
of the text area. If you use a fixed width font (ie, courier) you can
calculate the current row and column that the cursor is at, based upon
the x and y offsets of the event object relative to the X and Y
cooridinates and sizes of the textarea. Once you know the column and
row, you can use createTextRange to convert the text of the area into
a TextRange object. You can then manipulate the TextRange object to
grab the left characters before the cursor position, add the inserted
string, then add the right characters after the cursor, then replace the
.text of the textrange with your new text.
One obvious problems with this approach include large fonts may
screw up your location calculations.

Option two involves using the VB textbox as an ActiveX component for
your editing box, instead of a