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

How to highlight searched keywords

Guest
Apr 19, 2010 Apr 19, 2010

I'd like my keyword search results to be highlighted. I have a simple (wildcard) keyword search box on my dynamic pages with results appearing on the same page. The code is:

<%
Dim rs_lostcats__MMColParam
rs_lostcats__MMColParam = "%"
If (Request.Querystring("search") <> "") Then
  rs_lostcats__MMColParam = TRIM(Request.Querystring("search"))
End If
%>

.....and my form code is:  <input name="search" type="text" id="search" value="<%= Request.Querystring("search") %>" />

Can someone help?

TOPICS
Server side applications
2.3K
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
LEGEND ,
Apr 19, 2010 Apr 19, 2010

You can use VBScript Replace() function to replace the search term with the search term + formatting.

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
Apr 19, 2010 Apr 19, 2010

I've researched about that method, but since I don't write script, I'm not sure where or how to apply the Replace() function.  Would I add it to the script I've already got (listed above) or do I need a separate function?  And then would I write a Response.write function for the input field?  Thanks for your help again, I'm so darn close to achieving all I need for now....

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
LEGEND ,
Apr 19, 2010 Apr 19, 2010

>Would I add it to  the script I've already

>got (listed above) or do I need a separate  function?

You would need to add it to the script that outputs the results.

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
Apr 21, 2010 Apr 21, 2010

Okay, just getting back to this....  I'm trying different ways of writing this script according to samples I find on the web, but nothing has worked so far. 

Am I on the right track with something like this?

<%

Function Replace(search, “ “, <font color=”red”>” “</font>)

search = (Request.Querystring(“search”))

End Function

%>

....then on the search form field:

<input name="search" type="text" id="search" value="<%Response.Write search (<%= Request.Querystring("search") %>)" />

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
LEGEND ,
Apr 21, 2010 Apr 21, 2010

>Am I on the right track with something  like this?

Uh, no. You need to modify the page that outputs the recordset results, not the page with the user input form. Can you post that page?

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
Apr 21, 2010 Apr 21, 2010
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
LEGEND ,
Apr 21, 2010 Apr 21, 2010

OK, I need to see the code to tell you where to modify it.


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
Apr 21, 2010 Apr 21, 2010

I knew that! sorry... it's over 400 lines though -- is there a way to attach a .doc or something to my post?

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
Apr 21, 2010 Apr 21, 2010

Does any of this pertain or help?  I'm using a sort repeat region DW extension that creates a LOT of code.

<%

Dim rs_lostcats__MMColParam

rs_lostcats__MMColParam = "%"

If (Request.Querystring("search") <> "") Then

  rs_lostcats__MMColParam = TRIM(Request.Querystring("search"))

End If

%>

<%

Dim rs_lostcats__MMColParam2

rs_lostcats__MMColParam2 = "%"

If (Request.Querystring("search") <> "") Then

  rs_lostcats__MMColParam2 = TRIM(Request.Querystring("search"))

End If

%>

<%

Dim rs_lostcats__MMColParam3

rs_lostcats__MMColParam3 = "%"

If (Request.Querystring("search") <> "") Then

  rs_lostcats__MMColParam3 = TRIM(Request.Querystring("search"))

End If

%>

<%

Dim rs_lostcats__MMColParam4

rs_lostcats__MMColParam4 = "%"

If (Request.Querystring("search") <> "") Then

rs_lostcats__MMColParam4 = TRIM(Request.Querystring("search"))

End If

%>

<%

'sort column headers for rs_lostcats

Dim tfm_saveParams, tfm_keepParams, tfm_orderbyURL

tfm_saveParams = "search"

tfm_keepParams = ""

If tfm_order = "ASC" Then

            tfm_order = "DESC"

Else

            tfm_order = "ASC"

End If

                       

If tfm_saveParams <> "" Then

            tfm_params = Split(tfm_saveParams,",")

            For i = 0 to UBound(tfm_params)

                        If Cstr(Request(tfm_params(i))) <> "" Then

                                    tfm_keepParams = tfm_keepParams & LCase(tfm_params(i)) & "=" & Server.URLEncode(Request(tfm_params(i))) & "&"

                        End If

            Next

End If

tfm_orderbyURL = Request.ServerVariables("URL") & "?" & tfm_keepParams & "tfm_order=" & tfm_order & "&tfm_orderby="

%>

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
Apr 21, 2010 Apr 21, 2010

I'll try to attach a Word doc with all the code

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
LEGEND ,
Apr 21, 2010 Apr 21, 2010

OK good. In the mean time, why do you have 4 query parameters. There is only one search term, correct?

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
Apr 21, 2010 Apr 21, 2010

It appears I can't attach a document to a post.

Earlier when you helped me, we discussed why I have four query parameters for one search term - it's because I get an error message through DW if I only have one.  Illogical, but I figure if four works, fine.

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
Apr 21, 2010 Apr 21, 2010

I'll PM the script to you if you'd like.  I don't feel comfortable publicizing it.

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
LEGEND ,
Apr 21, 2010 Apr 21, 2010

> it's because I get an error message through DW if I only have one

OK, you'll really should figure out why that is. Go ahead and send me the file via pm if you can.

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
Apr 23, 2010 Apr 23, 2010

I PM'ed the code

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
LEGEND ,
Apr 23, 2010 Apr 23, 2010

Sorry, but that code does not contain the part that sends output to the browser. I need to see that code - that's where you would alter it to add highlighting. Rather than trying to attach it to this thread, save a copy of your pages with a .txt extension, upload and send the url. Make sure you don't have any credentials in that code.

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
Apr 23, 2010 Apr 23, 2010

Okay, I'm sorry, I guess I assumed the entire code (minus VBScript) could be viewed via "view source" on the link to my website page I posted earlier.  I'll PM the URL for the .txt file.

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
LEGEND ,
Apr 26, 2010 Apr 26, 2010

Yeah, only the code sent to the client is viewable - any server side scripting is not. I just took a look at the code and will send you a few suggestions.

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
Apr 27, 2010 Apr 27, 2010

You're AWESOME!  It's working like a charm.  Since I have four separate parameters for one search, I'll

need to create the same for all.  I know that seems ridiculous, but it's the only way it'll work for me without errors You must love to help people, love animals, or both!  Thank you so much...

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
Apr 27, 2010 Apr 27, 2010

One more thing, is there a way to make it case-insensitive? It's displaying records but not highlighting words with capped first letters unless the search is specified capped...

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
LEGEND ,
Apr 27, 2010 Apr 27, 2010

Yes, replace can be made case insensitive.Just change the code to this:

            CatDetails = Replace (CatDetails,rs_lostcats__MMColParam, "<span class=""highlightsearch"">" & rs_lostcats__MMColParam & "</span>", 1, -1, 1 )


Keep in mind that this function replaces what is found with what the user types in. So if the user enters 'FLUFFY' but the contents is 'fluffy', all occurances will be displayed as 'FLUFFY'.

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
Apr 27, 2010 Apr 27, 2010

Works great, but yeah, I see what you mean. Is there a fix for that? I'll have to give it some thought and figure out what's more important, I guess, or put a note "case sensitive" under my search box.

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
LEGEND ,
Apr 27, 2010 Apr 27, 2010

The fix would be a more complex function that you would need to build. Thankfully, you already found one as mentioned in your PM. That's exactly how I would have done it.

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
Apr 27, 2010 Apr 27, 2010
LATEST

Knowing I have a fallback in the way you've provided which works fine and is much appreciated, I can try the other method for kicks.  Would these be my correct parameters?

Parameters:
' strText        - string to search in
' strFind        - string to look for
' strBefore      - string to insert before the strFind
' strAfter       - string to insert after the strFind
'

My Parameters:

' strText                  rs_lostcats.Fields.Item("Details").Value

' strFind                  rs_lostcats__MMColParam
' strBefore               <style=”background-color: #FFCC00;”
' strAfter                  </style>

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