Solved

Field that has HTML displays the code instead of the text in html

Posted on 2016-09-12
16
78 Views
Last Modified: 2016-09-12
I have an ASP page which displays 'notes'.  This notes were saved in HTML in the DB. Like :  Hello I am <strong> Joe Doe</strong>
When I display the field on the ASP page it shows as  Hello I am <strong> Joe Doe</strong>
Instead of making the name 'blank'  like:    Hello I am  Joe Doe

How can I display the text correctly and not the code 'behind'  it ?
0
Comment
Question by:amucinobluedot
  • 7
  • 4
  • 3
  • +1
16 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 41794312
It sounds like you are escaping the HTML before you send it to the browser.  How are you emitting that text onto the browser?
0
 

Author Comment

by:amucinobluedot
ID: 41794328
I am using a stored procedure. Attached is the code for that page.  

This is the portion of the SP that selects the notes that are displayed:

  STUFF( (SELECT Comments + ' | ' 
                             FROM casecomments b
                              WHERE  b.caseid = a.id
                             ORDER BY lastupdate
                             FOR XML PATH('')) , 
                            1, 0, '') AS casenotes,

Open in new window

code.txt
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 41794354
Try:

Response.Write "Hello I am <strong> Joe Doe</strong>"

That should output the bold in that string
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 82

Expert Comment

by:hielo
ID: 41794399
In XML the less than, greater than, and ampersand characters have "special meaning", so they would need to be escaped if you wanted them as part of the data.  Your query has a "FOR XML" clause, so most likely  it is escaping the less and greater than symbols contained in the Comments field.

Try changing:
<%=(report_results.Fields.Item("casenotes").Value)%>

Open in new window


to:
<%= Replace(Replace(Replace(report_results.Fields.Item("casenotes").Value, "&lt;","<"),"gt;",">"),"<script","") %>

Open in new window

0
 
LVL 54

Accepted Solution

by:
Julian Hansen earned 250 total points
ID: 41794403
Sounds like your data is encoded in the database which means you have to decode it before sending to the browser
Example
Function HTMLDecode(html)
    html = Replace(html, "&quot;", Chr(34))
    html = Replace(html, "&lt;"  , Chr(60))
    html = Replace(html, "&gt;"  , Chr(62))
    html = Replace(html, "&amp;" , Chr(38))
    html = Replace(html, "&nbsp;", Chr(32))
    HTMLDecode = html
End Function

dim s
s = "&lt;strong&gt;Jon Doe&lt;/strong&gt;"
Response.Write HTMLDecode(s)
%>	

Open in new window

0
 

Author Comment

by:amucinobluedot
ID: 41794405
I got this error:

Microsoft VBScript runtime error '800a005e'

Invalid use of Null: 'Replace'

/bluedot/Intranet/reports/rp_all_01_results.asp, line 408
0
 

Author Comment

by:amucinobluedot
ID: 41794417
Julian,

How do I apply that function and I got this error:

Microsoft VBScript runtime error '800a005e'

Invalid use of Null: 'Replace'

/bluedot/includes/bdot/scripts.asp, line 428 

Open in new window


This is on the script's first line.  Some of the fields are null some have data.

I am trying to display the content with:

<%=HTMLDecode(report_results.Fields.Item("casenotes").Value)%>
0
 
LVL 33

Expert Comment

by:Big Monty
ID: 41794424
sorry my last answer was incomplete, try this if only your code isn't encoded when you save it.

Response.Write Server.HTMLEncode( "Hello I am <strong> Joe Doe</strong>" )

If the data IS encoded, you'll have to manually decode it using the clean function I gave you awhile back
0
 

Author Comment

by:amucinobluedot
ID: 41794442
Big Monty:  I tried using the code we have to 'clean' (using in the other post) but the text still looks the same:


G-28, I-129 emailed to amucino'23@demo.com as PDF by Attorney Name. | &lt;p&gt;tseefe&lt;/p&gt; | &lt;p&gt;Please make sure you add comments to this case visible to both&lt;/p&gt; | &lt;p&gt;Add comments to this case here one visible indv not and low&lt;/p&gt; | &lt;p&gt;test&lt;/p&gt; | &lt;p&gt;test 2&lt;/p&gt; |
0
 
LVL 82

Expert Comment

by:hielo
ID: 41794443
If the field contains nulls, then use:
<%
If NOT IsNull(report_results.Fields.Item("casenotes").Value) Then
Response.Write( Replace(Replace(Replace(report_results.Fields.Item("casenotes").Value, "&lt;","<"),"gt;",">"),"<script","") )
End If
%>

Open in new window

0
 

Author Comment

by:amucinobluedot
ID: 41794451
Tried the above and still got error:

Microsoft VBScript runtime error '800a005e'

Invalid use of Null: 'Replace'

/bluedot/Intranet/reports/rp_all_01_results.asp, line 411

I also tried:

If NOT IsNull(report_results.Fields.Item("casenotes").Value) Then
HTMLDecode(report_results.Fields.Item("casenotes").Value)

and got the same above error.
0
 
LVL 82

Assisted Solution

by:hielo
hielo earned 250 total points
ID: 41794456
Regarding Julian's function do a null check within the HTMLDecode
Function HTMLDecode(html)
    HTMLDecode=""
   If NOT IsNull(html) Then
    html = Replace(html, "&quot;", Chr(34))
    html = Replace(html, "&lt;"  , Chr(60))
    html = Replace(html, "&gt;"  , Chr(62))
    html = Replace(html, "&amp;" , Chr(38))
    html = Replace(html, "&nbsp;", Chr(32))
    HTMLDecode = html
  End If
End Function

<%=HTMLDecode(report_results.Fields.Item("casenotes").Value)%>

Open in new window

0
 

Author Comment

by:amucinobluedot
ID: 41794458
PERFECT !  That addition worked. Thank you everyone!  I will go ahead and share the points I hope thats ok with everyone.
0
 

Author Closing Comment

by:amucinobluedot
ID: 41794461
Thank you !
0
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 41794493
How are you trying to apply it - what does your code look like?
You can see the code above working here
0
 
LVL 54

Expert Comment

by:Julian Hansen
ID: 41794504
You are welcome.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delete HTML table rows 12 29
Java script read and write file - save as location 8 45
hosting images 4 29
Grunt script for Build Process 1 29
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

809 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