Forum Moderators: open
I wish to replace request("q") with " <strong> " & request("q") & " </strong> "
I wish to use on a search engine which I just built, this command will highlight the keyword the user selected. When I place this command at the top of my asp block, will it place strong round the title because if it does <strong> will appear in the title bar and if it does how do I resolve the problem.
cmatcme
User searches for example.
Search results for example:
Example webpage:
This is an example webpage created by example.com
http://example.com/examplewebpage.asp
Something like that and if the user were to type in webpage it would bolden all "webpage" on the page.
cmatcme
<%
DIM bolden
bolden = request("q")
response.write replace(bolden, "example","<strong> example </strong>")
%> But there is one problem with it and that is that it doesn't apply to the whole page, only a variable and it will only replace a phrase inside the variable with something else. Is there a way to make it apply with the whole page? Additionally, the text is inside a variable, will it replace that too?
cmatcme
searchToken = Request("q")
public function MakeBold(in_dbString, in_originalRequest)
Dim retVal
if in_dbString = in_originalRequest then
retVal = "<strong>" & in_dbString & "</strong>"
else
retVal = in_dbString
end if
MakeBold = retVal
end function
for x = lbound(aResults,2) to ubound(aResults,2)
Response.Write MakeBold(aResults(0,x), searchToken)
next
The code:
<%
searchToken = Request("q")
public function MakeBold(in_dbString, in_originalRequest)
Dim retVal
if in_dbString = in_originalRequest then
retVal = "<strong>" & in_dbString & "</strong>"
else
retVal = in_dbString
end if
MakeBold = retVal
end function
for x = lbound(aResults,2) to ubound(aResults,2)
Response.Write MakeBold(aResults(0,x), searchToken)
next
%> Hello I think <% = request("q") %> is really cool. Everyone likes <% = request("q") %>.
<% = request("q") %> rules! [/code]
returns...
Type mismatch lbound
Any ideas?
cmatcme
That code is much appreaciated!
You need to populate your array that you mentioned you had. Then make sure the name of your array lines up with the name I put into that code.
This sample populates the array with sample junk:
searchToken = request("q")
public function MakeBold(in_dbString, in_originalRequest)
Dim retVal
if lcase(in_dbString) = lcase(in_originalRequest) then
retVal = "<strong>" & in_dbString & "</strong>"
else
retVal = in_dbString
end if
MakeBold = retVal
end function
Dim aResults
ReDim aResults(0,4)
aResults(0,0) = "Test"
aResults(0,1) = "to"
aResults(0,2) = "see"
aResults(0,3) = "me"
aResults(0,4) = "work"
for x = lbound(aResults,2) to ubound(aResults,2)
Response.Write MakeBold(aResults(0,x), searchToken) & "<br>"
next