How to highlight the search keyword from the search result?

Dear EE experts,

We would like to ask for tech support on how to highlight the Search Keyword from the search results. How to BOLD it?
For example, if user search: AQ , and from the results there are AQ Series, Aqua Series, Aquatic Image, we would like the keyword "AQ" or "Aq" be bold.

Thank you!
Stiebel EltronAsked:
Who is Participating?
 
teebonConnect With a Mentor Product ManagerCommented:
Hi Stiebel,

use vbscript replace function:

<%=Replace(rsProducts("series_name"),requestSeries,"<b>" & requestSeries & "</b>") %>

Open in new window

0
 
Stiebel EltronAuthor Commented:
Sorry, here's the script:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim myConnection, rsProducts
Dim connectString
Dim sqlContent
Dim requestSeries

connectString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=SERVER; PORT=PORT; DATABASE=DB; USER=UN; PASSWORD=PW; OPTION=0;"

Set myConnection = Server.CreateObject("ADODB.Connection")
Set rsProducts = Server.CreateObject("ADODB.Recordset")

'SeriesID = Request.QueryString("SeriesID")
myConnection.Open connectString

requestSeries = Request.Form("Series")

      sqlContent = "Select * From series WHERE series_name LIKE '%" & requestSeries &"%'"
      
      Set rsProducts = myConnection.Execute(sqlContent)
      
      If (rsProducts.BOF) AND (rsProducts.EOF) then
            Response.Write("Sorry, but Product Series " & requestSeries & " was not found.")
            
      Else      
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />

<meta name="GENERATOR" content="Mozilla/4.7 [en] (Win98; I) [Netscape]" />


<title>..:: Stiebel Eltron's iPhoto Stock Gallery - Powered by STE IT Dept. ::..</title>


</head>

<body bgproperties="fixed" bgcolor="#000000" onload="javascript:startmenu()">
<table width="760" border="0" cellspacing="3" cellpadding="1">
  <tr>
    <td><img src="IMG/logo_res.jpg" alt="STIEBEL ELTRON" /></td>
    <td valign="top" bgcolor="#666666">
          <SCRIPT LANGUAGE="JavaScript">
          <!-- Begin
            showImage();
            //  End -->
            </script>
    </td>
    <td><img src="IMG/white_square.png" alt="STIEBEL ELTRON" /></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="right" bgcolor="#999999"><font face="Verdana, Geneva, sans-serif" color="#FFFFFF">
    <%
   '// If user is logged in show name and logout link
   If Session("loggedin") = true Then
      Response.Write "Welcome: " & Session("FName")
      Response.Write "<br /><a href=""login/logout.asp"">Logout</a>"
   Else
      Response.Write "<a href=""ste-iphoto-login2.asp"" title=""CLICK TO LOGIN"">REGISTERED USERS</a>"
   End If
      %>&nbsp;
      </td>
    <td bgcolor="#666666" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
   
    <td align="left" bordercolor="#999999" bgcolor="#FFFFFF">
          Search request result from the keyword: <b><% Response.Write("" & requestSeries & "") %></b>
      </td>
      <td bgcolor="#999999" align="center">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
   
      <td align="left" bordercolor="#999999" bgcolor="#FFFFFF">
<table width="100%" border="0" cellspacing="3" cellpadding="1">
      <tr>
          <td bgcolor="#999999" align="center">
        ID
        </td>
          <td bgcolor="#999999" align="center">
        SERIES NAME
        </td>
          <td bgcolor="#999999" align="center">
        LINK
        </td>
      </tr>
   
    <!-- Get Data -->
    <% do while not rsProducts.EOF %>
   
    <tr>
          <td align="center" class="td2" bgcolor="#CCCCCC">
              <%=rsProducts("categoryid")%>
        </td>
          <td class="td2" bgcolor="#CCCCCC">
              <%=rsProducts("series_name")%>
        </td>
          <td class="td2" bgcolor="#CCCCCC">
              <%
                  if rsProducts("categoryid") = 2 then
                  %>
            <a href="http://www.cssasia.info/ste/ste-search-result.asp?SeriesID=<%=rsProducts("seriesid")%>">Shower Unit</a>
            <%
                  
                  end if
                  %>
        </td>
    </tr>
    <% rsProducts.MoveNext %>
    <% loop %><!--Next Row-->

</table>
0
 
Stiebel EltronAuthor Commented:
Hi there teebon!

Thank you for your response, but to which line do we need to put that REPLACE line?
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
Stiebel EltronAuthor Commented:
Got it! Sorry...
0
 
Stiebel EltronAuthor Commented:
Excellent!
0
 
Stiebel EltronAuthor Commented:
Hello to you again teebon!

Just want to ask, why does it stops to highlight the search keyword?
earlier it's working just fine, but after few hours of testing, we noticed that the highlight of every keyword isn't working again...
we're still using this line: <%=Replace(rsProducts("series_name"),requestSeries,"<b>" & requestSeries & "</b>") %>
0
 
Stiebel EltronAuthor Commented:
ah ok, we found the problem, the keyword should be SAME with the search result. The uppercase and lower case of each letter should be the same, otherwise it won't highlight at all...
0
 
teebonProduct ManagerCommented:
Has the code been modified again?
Are you testing on the same server?
0
 
teebonProduct ManagerCommented:
Hi stiebel,

try to add one more parameter as below:

<%=Replace(rsProducts("series_name"),requestSeries,"<b>" & requestSeries & "</b>",,,1) %>

Open in new window

0
 
Stiebel EltronAuthor Commented:
hi teebon! thanks for your reply.
We didn't modify the codes.
We follow what you advised, replace the previous script with the new one, but with the latest, we received error result.

"An error occurred on the server when processing the URL. Please contact the system administrator.
If you are the system administrator please click here to find out more about this error."

So we go back with this line of script: <%=Replace(rsProducts("series_name"),requestSeries,"<b>" & requestSeries & "</b>") %>

that you advised earlier...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.