Skip to main content
August 18, 2007
Answered

highlight search result

  • August 18, 2007
  • 3 replies
  • 718 views
have asp search page with multiple search forms. searching access data base. on the results page, i want the search values to be highlighted (color:red).
so when a user enters 'rub'

the results would be Rubbermaid with the Rub appearing in red.

thanks for any help or point me in the right direction
This topic has been closed for replies.
Correct answer
replace function is correct. using VBScript. thanks for your help.

'here is what i ended up with'
<%

Function HilightResults(sDataValue, sSearchString)
HilightResults = Replace(UCase(sDataValue), UCase(sSearchString), "<span style='color:red;'>" & UCase(sSearchString) & "</span>")
End Function

%>
'and this is the td span'
<td class="WADAResultsTableCell"><%=HilightResults((WADALABEL1.Fields.Item("Item_number").Value), Request("S_Item_number"))%></td>

3 replies

Correct answer
August 20, 2007
replace function is correct. using VBScript. thanks for your help.

'here is what i ended up with'
<%

Function HilightResults(sDataValue, sSearchString)
HilightResults = Replace(UCase(sDataValue), UCase(sSearchString), "<span style='color:red;'>" & UCase(sSearchString) & "</span>")
End Function

%>
'and this is the td span'
<td class="WADAResultsTableCell"><%=HilightResults((WADALABEL1.Fields.Item("Item_number").Value), Request("S_Item_number"))%></td>
Inspiring
August 18, 2007
David Powers wrote:
> jim balthrop wrote:
>> have asp search page with multiple search forms. searching access
>> data base. on the results page, i want the search values to be
>> highlighted (color:red).
>
> I don't know the ASP syntax for doing it, but you need to use a string
> method to replace the search term with a span tag containing a CSS class
> wrapped around the term. You get the search term from the query string.
> In pseudocode:
>
> highlighted = replace(search_term, '<span
> class="highlight">'+search_term+'</span>, result);
> display highlighted;
>
> In PHP, you would use str_replace(). I'm sure ASP has a similar string
> function/method.

replace function in VBScript and, IIRC, the same in JavaScript
Inspiring
August 18, 2007
jim balthrop wrote:
> have asp search page with multiple search forms. searching access data base.
> on the results page, i want the search values to be highlighted (color:red).

I don't know the ASP syntax for doing it, but you need to use a string
method to replace the search term with a span tag containing a CSS class
wrapped around the term. You get the search term from the query string.
In pseudocode:

highlighted = replace(search_term, '<span
class="highlight">'+search_term+'</span>, result);
display highlighted;

In PHP, you would use str_replace(). I'm sure ASP has a similar string
function/method.

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/