Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

startposition of selected text ???

Status
Not open for further replies.

Moonrider

Programmer
Oct 30, 2001
12
0
0
BE
function sel_text()
{
var selectedHTML = document.selection.createRange().htmlText;
alert(document.selection.createRange().selectionstart);
var allHTML = document.all.FirstCol.innerHTML;
var LinksZahl = allHTML.indexOf(selectedHTML, document.selstart);
var Links = allHTML.substr(0,LinksZahl);
var Rechts = allHTML.substr(LinksZahl + selectedHTML.length, allHTML.length);
var Gesamt = Links + &quot; <span style='background-color:yellow'>&quot; + selectedHTML + &quot;</span> &quot; + Rechts;
document.all.FirstCol.innerHTML = Gesamt;
}

Hi !
I wrote this function in JavaScript
as far as I know it only works in IE
that doesnt matter to me because it's
supposed just to run on my intranet.
Here my question:
When I select for instance the word &quot;deployment&quot;
in my browser
and it is the second time in the text
its just the first &quot;deployment&quot; that will be
marked in yellow color.
I know indexof works also with a startposition
but I dont know how to find out where my selected
text starts.

FirstCol is the id of a tablecell
and so far it works perfect just with that
little problem

Thanks for your help
Moonrider
 
the 2nd line
&quot;alert(document.selection.createRange().selectionstart);
&quot;
of the function doesn't work
I forgot to remove it
 
I didn't try yet !!!

But anyway : THANK YOU VERY MUCH

as soon as my script runs I will post it

:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top