Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Selecting HTML on screen and text in a textbox


Message #1 by "JP Davey" <jpdavey@a...> on Mon, 3 Jun 2002 21:17:27
I have a span and a textbox that have identical text strings - actually, 
the span reflects what's in the textbox.  I'm trying to select text in the 
span with the mouse and onmouseup make it select the matching text in the 
textbox.  Can this even be done?  I've tried ye ol'

a=document.selection.createRange();
b=formname.textboxname.createTextRange();
b.select(a.text);

but that only selects the first instance of the a.text string in the 
textbox - not the correct matching text.  I've also tried the b.setEndPoint
("StartToStart",a) and b.setEndPoint("EndToEnd",a) but that gave me an 
error.  Is there a way to find out how far into the span text the 
selection starts and ends then make it select the same text in the textbox?

  Return to Index