views:

1339

answers:

1

I have an app that lets the user search over a number of fields for a string, When they view the detail record, they would like all occurrences of the string to be highlighted.

The detail form is made up of Labels and ListViews, most of which live inside of TabPanels (from the AJAX Control Toolkit). I'd like to avoid the use of brute force to manually parse each value to add the highlighting tags before displaying it.

Is there a way to load my form and then parse the HTML? Is there another way around this?

+5  A: 

How about JavaScript and JQuery? http://plugins.jquery.com/project/highlight

I just tried that plugin out and it worked. You can specify which tags you want to highlight, and which words.

<script language="javascript" type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<script language="javascript" type="text/javascript" src="js/jquery.highlight-2.pack.js"></script>
<script language="javascript" type="text/javascript">
$(document).ready( function () {
    $('p').each(function() { $.highlight(this, 'LOREM'); });
});
</script>
<style type="text/css">
    .highlight { background-color: yellow }
</style>

..
..
..
    <p>
    Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi gravida risus elementum tortor. Duis mattis, est et volutpat cursus, mi mi ornare tortor, sed fringilla nibh erat sed eros. In nec orci vel velit scelerisque ultrices. Nunc auctor elit. Proin orci ligula, luctus a, venenatis sit amet, laoreet a, mauris. Suspendisse sem nibh, interdum eu, vestibulum non, semper vel, mauris. In quis leo suscipit risus semper pretium. Cras interdum iaculis dui. Etiam vel ipsum eu sapien dapibus sagittis. Donec lobortis, lectus et placerat euismod, quam dui porttitor sem, sed fermentum eros quam ac ipsum. Ut eu augue. Nullam lacinia dictum neque. Nullam eros. Phasellus sem nisi, feugiat nec, consectetur vel, ullamcorper at, nisl. Aenean quam risus, ullamcorper a, ultricies ut, posuere ac, quam. Vestibulum sed lectus ac orci fermentum viverra. Sed aliquam. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
    </p>
MrChrister
http://johannburkard.de/blog/programming/javascript/highlight-javascript-text-higlighting-jquery-plugin.html is the guys homepage with some examples.
MrChrister
+1 but should be $('p').each(function() { $(this).highlight('LOREM'); });
David G
No need to do a loop here, just a simple `$("p").highlight('LOREM')`
Chris Barr