PDA

View Full Version : Dynamic highlight of text using mouse in HTML page



smiles78
08-14-2008, 07:11 PM
I'm writing a web application and one of the things it has to do is the ability for a user to highlight text on a page dynamically. For instance, if there is the sentence 'My mom is a very pretty lady' and the instructions are to highlight the nouns in the sentence. The user would use the mouse and highlight 'mom' and 'lady'. The background for those words would turn yellow. Then the user clicks a submit button and the page verifies what is highlighted is indeed the nouns.

Eventually I will have to have the user highlight a bunch of terms then add them to some type of list (stored in the database).

Medyman
08-15-2008, 02:57 PM
It's possible to do that. I don't know how exactly, but I've seen it done.

These pages will be of help, however.

http://www.quirksmode.org/dom/range_intro.html
http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html
http://www.quirksmode.org/css/selection.html

Particularly, the first one.