Selecting text in a textbox

  • Thread starter Thread starter JJ
  • Start date Start date
J

JJ

I have a textbox that is used to insert some html code. I want to highlight
errors in the code, possibly by selecting the text.

Is it possible to highlight/select areas of a textbox programmatically?

Thanks,

JJ
 
You can select only one block of text in a web page, as the web page has
only one selection object, regardless of the browser. So, yes, you can
select text in a textbox using JavaScript. It's not easy, but it can be
done. How it is done depends on the client browser, as IE and Mozilla have
different implementations of the selection object and the range ("TextRange"
in IE) object.

Here are a couple of articles that deal with the subject with IE and FireFox
respectively:

http://www.bazon.net/mishoo/articles.epl?art_id=1292
http://www.dotvoid.com/view.php?id=11

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
I have a textbox that is used to insert some html code. I want to highlight
errors in the code, possibly by selecting the text.

Is it possible to highlight/select areas of a textbox programmatically?

Thanks,

JJ

It's possible use :
textbox.select()
Omar Abid
 
Back
Top