View Full Version : keyword highlighting
jsbinus
07-29-2003, 04:05 AM
Hi...Can anyone tell me what is the best way to highlight all the "keywords" in a page. Assuming that the keywords are passed through a query string. Can we achieve that by using javscript, if we can, how can we call from the server side script
Thanks
SJ
glenngv
07-29-2003, 06:41 AM
I think it's better to do it in server-side alone, like what this forum does. What's your server-side language?
in vbscript, you'd do it like this:
kw = request.querystring("keyword")
content = replace(content,kw,"<font color=""red"">" & kw & "</font>")
response.write(content)
or use span tag instead since font tag is deprecated
<span style="color:red">keyword</span>
fredmv
07-29-2003, 07:26 AM
glenngv: Shouldn't the double quotes be escaped? Or just use single-quotes inside replace...
glenngv
07-29-2003, 08:43 AM
you mean like this?
<%
kw = request.querystring("keyword")
content = replace(content,kw,"<span style='color:red'>" & kw & "</span>")
response.write(content)
%>
you could do it that way, but to stick to standards, you should use double quotes in HTML attribute values. And to do that inside vbscript string literals, you need to double the quotes to escape it.
<%
kw = request.querystring("keyword")
content = replace(content,kw,"<span style=""color:red"">" & kw & "</span>")
response.write(content)
%>
fredmv
07-29-2003, 09:06 AM
Oh alright, I was just wondering... Haven't done much coding in VBScript, JavaScript is so much better.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.