Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Highlight keyword in search results.

Guest
Nov 08, 2007 Nov 08, 2007
Greetings

I did this before and can't seem to replicate the code- but,

1) pass the form variable "form.keyword" to the results page
2) check that it exists (<cfif isDefined ....>)
3) the page header has: <style type="text/css">.highlight{background-color:yellow;}
</style>
4) highlight the keyword in the results page- that's it- nothing fancy- e.g. it's ok if searching for "cement" returns the word "replacement".

Thanks in advance!
1.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 08, 2007 Nov 08, 2007
I usually just use ReplaceNoCase; have it replace all the instances of the selected word with the word + a <span> tag around it with the required style class.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 08, 2007 Nov 08, 2007
Thanks for the quick response...

Could you reveal exactly how this would look on the display page?

the page is now:

<html>.......

<style type="text/css">.highlight{background-color:yellow;}
</style>
</head>
<body>
<cfquery name="findcode" datasource="vendors">
SELECT *
FROM all_cccode_lookup
WHERE cccode_desc LIKE '%#form.keyword#%'
</cfquery>


<font face="Verdana, Arial, Helvetica, sans-serif" size="+1" color="navy">
<p>Your search returned <cfoutput>#findcode.RecordCount#</cfoutput> code(s).</p>

<p>Results of your Search:</font></p>
<font face="sans-serif" size="1">
<cfoutput query="findcode">#cccode_num# - #cccode_desc#<br></cfoutput>


Thanks so much for your time....
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 09, 2007 Nov 09, 2007
I usually combine my output into 1 variable first so it makes it easier to do the replacing:

The only thing that really changes is the "output" part of the page.


<p>Results of your Search:</font></p>
<font face="sans-serif" size="1">

<cfoutput query="findcode">
<CFSET TheOutput = "#cccode_num# - #cccode_desc#">

#ReplaceNoCase("#TheOutput#","#form.keyword#","<span class=highlight>#form.keyword#</span>","ALL")#<br>
</cfoutput>


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Nov 09, 2007 Nov 09, 2007
Thanks Glen-

This works- (<CFSET> within the <cfoutput>)

<cfoutput query="findcode">
<CFSET TheOutput = "#cccode_num# - #cccode_desc#">
#ReplaceNoCase("#TheOutput#","#form.keyword#","<span class=highlight>#form.keyword#</span>","ALL")#<br></cfoutput>


Have a great weekend...
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Nov 09, 2007 Nov 09, 2007
LATEST


Take Care
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources