Copy link to clipboard
Copied
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?
Copy link to clipboard
Copied
You can use VBScript Replace() function to replace the search term with the search term + formatting.
Copy link to clipboard
Copied
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....
Copy link to clipboard
Copied
>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.
Copy link to clipboard
Copied
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") %>)" />
Copy link to clipboard
Copied
>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?
Copy link to clipboard
Copied
It's one in the same: http://www.petspathhome.com/lostcats_main.asp
Copy link to clipboard
Copied
OK, I need to see the code to tell you where to modify it.
Copy link to clipboard
Copied
I knew that! sorry... it's over 400 lines though -- is there a way to attach a .doc or something to my post?
Copy link to clipboard
Copied
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="
%>
Copy link to clipboard
Copied
I'll try to attach a Word doc with all the code
Copy link to clipboard
Copied
OK good. In the mean time, why do you have 4 query parameters. There is only one search term, correct?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I'll PM the script to you if you'd like. I don't feel comfortable publicizing it.
Copy link to clipboard
Copied
> 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.
Copy link to clipboard
Copied
I PM'ed the code
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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...
Copy link to clipboard
Copied
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'.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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>