from caret to textRange object

G

gm1974

Hi all,

in a DHTML Editing control (MSIE), I need to "extend" the caret to the
nearest text character in order to obtain a text selection (and than a
textRange object with the createRange method).

This is needed because I have a set of functions doing operations
within the edit control's rich text. But all the functions need to
start from a selected text (for example, adding a table row). My aim is
to get the things work also if no text is selected from the user. But I
could not find a way to have a selected text starting from the simple
cursor position. Any suggestion?

many thanks,

giovanni
 
B

Baconbutty

Hi

Hmm, not sure if this helps, or if I have understood correctly, but..

My understanding is that "document.selection" represents the current
selection or cursor position, and that a cursor is just a collapsed
range (i.e. same start and end point)..

http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/obj_selection.asp?frame=true

Thus:-

if (document.selection)
{
oCursorRange=document.selection.createRange();
}

You then use the MSIE TextRange methods

e.g.

oCursorRange.expand

http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/expand.asp

You can also do this:-

oCursorRange.collapse(true);// If you want to make sure it is
collapsed.

Does this help?

Julian
 

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

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top