Link to home
Start Free TrialLog in
Avatar of WeaveDaddy
WeaveDaddy

asked on

IF...THEN...not working with html memo field ASP/VBscript/DW

Hi Everyone:

I have a memo field in an Access database that contains html and special characters. If I write the value to the html page, all is well using...

<%=(Country.Fields.Item("CountryBackground").Value)%>

If I try to do a conditional statement like:

<% if (Country.Fields.Item("CountryBackground").Value) <>"" then %>
<%=(Country.Fields.Item("CountryBackground").Value)%>
<% end if %>

I get nothing to display even though the value is not empty. My best guess is that is has something to do with html or special characters that use "&"

I tried things like escape, urlencode, server.htmlencode, len...I may not have done them correctly.

How do I check to make sure a value exists before displaying to the page if there are special characters?

Any ideas?
Avatar of apresto
apresto
Flag of Italy image

<%
Response.Write "Field = " & Country.Fields.Item("CountryBackground").Value

if (Country.Fields.Item("CountryBackground").Value) <>"" then
   Response.write (Country.Fields.Item("CountryBackground").Value)
end if
%>

What is printed to the screen if you run this?  Field = ....
Avatar of eliavm
eliavm

Try adding <%@language=VBScript Codepage=1255%> to the top of the file.

Please write the full source of this asp file.

can u post ur ful code here ?
try trimming:

If Trim(Country.Fields.Item("CountryBackground").Value) <> "" then...

OR Len it:

If Len(Trim(Country.Fields.Item("CountryBackground").Value)) > 0 then...

see if those work
Avatar of WeaveDaddy

ASKER

apresto:

the response write displays the paragraphs in the memo field, but the if then statement displays nothing...the memo field contains "&rsquo;s" and other html

Is this why?
no, that shouldnt really have anything to do with it.  Try printing this to the screen:

Response.write "LEN = " & Len(trim(Country.Fields.Item("CountryBackground").Value))

it should give you the number of characters in the string, if this prints a number maybe we can use this method instead

did you say you have tried Server.HTMLencode( Country.Fields.Item("CountryBackground").Value )
LEN = 1524

Server.HTMLencode does not work

what about
<% if len(Country.Fields.Item("CountryBackground").Value) > 0 then %>
<%=(Country.Fields.Item("CountryBackground").Value)%>
<% end if %>
see if this helps you
sorry, @apresto write my solution first
seems like the len statement should work but it does not
what about
<% if not (isnull(Country.Fields.Item("CountryBackground").Value) or isempty(Country.Fields.Item("CountryBackground").Value)) then %>
<%=(Country.Fields.Item("CountryBackground").Value)%>
<% end if %>
stick an ELSE block in there and print the LEN again, just to see what the hells going on - this is strange

@John_Lennon - No worries :o)
It seems like after you do something conditional with the database value, the value exits or disappears because I have a normal write after the conditional write and the normal write no longer displays either...

<% if not (isnull(Country.Fields.Item("CountryBackground").Value) or isempty(Country.Fields.Item("CountryBackground").Value)) then %>
<%=(Country.Fields.Item("CountryBackground").Value)%>
<% end if %>


                    
<p><span class="style25"><%=(Country.Fields.Item("CountryBackground").Value)%></span></P>
try ....

<%
tmp=Country.Fields.Item("CountryBackground").Value
if tmp<>"" then
      Response.Write tmp
end if
%>
try this

strTemp = Country.Fields.Item("CountryBackground").Value
response.write strTemp & "<hr>"
if len(strTemp) > 0 then response.write "Has a value"
response.write len(strTemp) & "<br>"
if not isnull(strTemp) then response.write "has a value"
response.write isnull(strTemp) & "<br>"
if not isempty(strTemp) then response.write "has a value"
response.write isempty(strTemp) & "<br>"
if trim(strTemp) <> "" then response.write "has a value"
response.write trim(strTemp) & "<br>"

response.write "<hr>" & strTemp
at least one of this must be true
eliavm:

that worked... I was trying to avoid response.write for other reasons and was trying to break the statement. If I break the ASP and try to then write the data value as
<%
tmp=Country.Fields.Item("CountryBackground").Value
if tmp<>"" then %>
      <%=(Country.Fields.Item("CountryName").Value)%>
<%end if
%>

I lose the value

guess I'll have to use response.write
ASKER CERTIFIED SOLUTION
Avatar of eliavm
eliavm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
eliavm:
Both of your above scenarios work properly.

There's something definitely happening with trying to get the field value twice like below. Oh well...thanks everyone

<%
tmp=Country.Fields.Item("CountryBackground").Value
if tmp<>"" then %>
      <%=Country.Fields.Item("CountryName").Value%>
<%end if
%>