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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display searched TEXT... Help 2

Status
Not open for further replies.

TonyU

Technical User
Feb 14, 2001
1,317
US

Hello all.
I have a search page that searches a company field with whatever the user types. My questions is, how do I highlight or Bold the word types within my search.

Example: User, searches for "National" and my results display

Results 1: National Assoc. Lawyers
Results 2: Home Howners National Team

I would like the results to display
Home Howners National Team and so on..
Tony
:cool:
 
Use the replace function:

strResult = Replace(strText, strFind, &quot;<B>&quot; & strFind & &quot;</B>&quot;)

All occurances of the word will be wrapped with the bold tag. -Chris Didion
Matrix Automation, MCP
 
Use a regular expression. If it is in the search result, check for the pattern. When it finds searchVar, replace searchVar with &quot;<b>&quot; & searchVar & &quot;</b>&quot;. If you don't know regular expressions, it is part of the regexp object.

Here is a pattern I use as an examle...it doesn't completely fit your example but it does what generally what you are trying to do:
<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME=&quot;Generator&quot; CONTENT=&quot;EditPlus&quot;>
<META NAME=&quot;Author&quot; CONTENT=&quot;&quot;>
<META NAME=&quot;Keywords&quot; CONTENT=&quot;&quot;>
<META NAME=&quot;Description&quot; CONTENT=&quot;&quot;>
</HEAD>

<BODY BGCOLOR=&quot;#FFFFFF&quot;>
<script language=vbscript>
dim re, str, newstr
set re=new regexp

re.pattern=&quot;^\w+\s+(\w+)&quot;
str=&quot;i have a dog named joe.&quot;

if re.test(str) then
document.write &quot;Match&quot;
document.write &quot;<br>&quot;
'replace the match with
newstr=re.replace(str, &quot;<b>BINGo</b>&quot;)


document.write newstr
end if
</script>
</BODY>
</HTML>

You'd have to change the pattern here:
re.pattern=&quot;^\w+\s+(\w+)&quot;

so re.pattern= whatever you are trying to bold

That should basically do it.

Mike
 
Thanks for the help fellas, both worked just fine. Tony
:cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top