?
Solved

Highlight a word from some text

Posted on 2016-08-01
16
Medium Priority
?
75 Views
Last Modified: 2016-08-01
I have a page that displays text from a nvarchar (8000) field in my database as: <%=(report_results.Fields.Item("comments").Value)%>

I am also passing a 'keyword' from the previous page and I retrieve it with: request.form("keyword")  

I want to highlight the value I pass as keyword in the text that is displayed on the page.  Example:

I my keyword is "second"

I want the text to display as "This is the second time I try this"  or something of that nature. How can I do this ?

I am using SQL 2008 and ASP Classic
0
Comment
Question by:amucinobluedot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 8
16 Comments
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41738324
what you see in your page is generated and displayed as HTML. Hence, to highlight certain words based on certain actions, you need to change the HTML codes as well.

so, now the question is what is the container of that area to display your wordings? is it a DIV, etc? do you have the codes to post here?
0
 

Author Comment

by:amucinobluedot
ID: 41738332
Sure. This is the whole table where I have a repeated region showing the results.

 <table class="table table-striped table-bordered table-hover dataTables-example" >
                <thead>
                  <tr>
                    <th width="3%">Actions</th>
                    <th width="10%">User</th>
                    <th width="46%">Notes</th>
                    <th width="10%">Case number</th>
                    <th width="13%">Contact</th>
                    <th width="8%">Last updated</th>
                    <th width="10%">Case status</th>
                    </tr>
                </thead>
                <tbody>
                <% 
While ((Repeat1__numRows <> 0) AND (NOT report_results.EOF)) 
%>
                    <tr class="gradeX">
                      <td><a href="../cases/notes_index.asp?caseId=<%=(report_results.Fields.Item("caseid").Value)%>" target="_blank" class="btn btn-white btn-sm"><i class="fa fa-folder" text-navy></i></a></td>
                      <td><%=(report_results.Fields.Item("atty").Value)%></td>
                      <td><%=(report_results.Fields.Item("comments").Value)%></td>
                      <td><%=(report_results.Fields.Item("caseid").Value)%></td>
                      <td><%=(report_results.Fields.Item("Alien").Value)%></td>
                      <td><%= DoDateTime((report_results.Fields.Item("Lastupdate").Value), 2, 9225) %></td>
                      <td><%=(report_results.Fields.Item("casestatus").Value)%></td>
                    </tr>
                                    <% 
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  report_results.MoveNext()
Wend
%>
                </tbody>
                <tfoot>
                  <tr>
               <th width="3%">Actions</th>
                    <th width="10%">User</th>
                    <th width="46%">Notes</th>
                    <th width="10%">Case number</th>
                    <th width="13%">Contact</th>
                    <th width="8%">Last updated</th>
                    <th width="10%">Case status</th>
                    </tr>
                    

                </tfoot>
              </table>

Open in new window


The field that will include the text that should highlight any matching keywords is: <%=(report_results.Fields.Item("comments").Value)%>

Let me know if you need anything else.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41738335
is that the content of report_results.Fields.Item("comments").Value is plain text or already in HTML?
0
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 

Author Comment

by:amucinobluedot
ID: 41738337
It is HTML code. User saves the content from an HTML editor, this is an example:

<p><strong>Client is traveling to:</strong> <span style="color:#ff0000">This is an example of a note</span></p><p>From:<br />To:</p><p>Additional comments:&nbsp;</p>

Open in new window


This is another example where user doesn't do anything other than enter text in the editor

test note no styling

Open in new window

0
 
LVL 53

Accepted Solution

by:
Ryan Chong earned 2000 total points
ID: 41738367
you probably can refer to this article:

Keyword highlighting in ASP
http://www.codeproject.com/Articles/610/Keyword-highlighting-in-ASP

then try something like:
<%=Highlight(report_results.Fields.Item("comments").Value, "second"  , "<font color=red><b>", "</b></font>"  )%>

Open in new window

0
 

Author Comment

by:amucinobluedot
ID: 41738400
I made a mistake and closed the question. Unfortunately it didn't work, it doesnt highlight the word  :$
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41738402
let me try and get back to you shortly..
0
 

Author Comment

by:amucinobluedot
ID: 41738404
Sounds good. Same result with other browsers
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41738407
simple test looks good:
<%


text = "<p><strong>Client is traveling to:</strong> <span style=""color:#ff0000"">This is an example of a note</span></p><p>From:<br />To:</p><p>Additional comments:&nbsp; whatever this is second ++ </p>"

response.write Highlight(text, "second"  , "<font color=red><b>", "</b></font>"  )

Function Highlight(strText, strFind, strBefore, strAfter)
	Dim nPos
	Dim nLen
	Dim nLenAll
	
	nLen = Len(strFind)
	nLenAll = nLen + Len(strBefore) + Len(strAfter) + 1

	Highlight = strText

	If nLen > 0 And Len(Highlight) > 0 Then
		nPos = InStr(1, Highlight, strFind, 1)
		Do While nPos > 0
			Highlight = Left(Highlight, nPos - 1) & _
				strBefore & Mid(Highlight, nPos, nLen) & strAfter & _
				Mid(Highlight, nPos + nLen)

			nPos = InStr(nPos + nLenAll, Highlight, strFind, 1)
		Loop
	End If
End Function

%>

Open in new window


>>Ok. For some reason it only highlited in red the first time I did it, then the results page keeps highlighting that one word.
Do you have a screenshot to share here?
0
 

Author Comment

by:amucinobluedot
ID: 41738416
Well I think the problem is that I copy/pasted the code. It is always using 'second' to highlight, I should change it to the value of the form

<%=Highlight(report_results.Fields.Item("comments").Value, "second"  , "<font color=red><b>", "</b></font>"  )%>

Open in new window


How can I replace 'second'  for <%=request.form("keyword")%>   ?
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41738419
alright, I think you got the problem resolved.
0
 

Author Comment

by:amucinobluedot
ID: 41738421
Not 100% ... just need a little help with the syntax to use the form value instead of the hard coded value of 'second'
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41738429
alright, so try this:
<%=Highlight(report_results.Fields.Item("comments").Value, request.form("keyword")  , "<font color=red><b>", "</b></font>"  )%>

Open in new window

0
 

Author Comment

by:amucinobluedot
ID: 41738433
Awesome !  thanks so much. all set here.
0
 
LVL 53

Expert Comment

by:Ryan Chong
ID: 41738434
coool, glad that it works!
0
 

Author Comment

by:amucinobluedot
ID: 41738435
It does, perfectly. Have a good night!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question