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("C ountryBack ground").V alue)%>
If I try to do a conditional statement like:
<% if (Country.Fields.Item("Coun tryBackgro und").Valu e) <>"" then %>
<%=(Country.Fields.Item("C ountryBack ground").V alue)%>
<% 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?
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("C
If I try to do a conditional statement like:
<% if (Country.Fields.Item("Coun
<%=(Country.Fields.Item("C
<% 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?
Try adding <%@language=VBScript Codepage=1255%> to the top of the file.
Please write the full source of this asp file.
Please write the full source of this asp file.
can u post ur ful code here ?
try trimming:
If Trim(Country.Fields.Item(" CountryBac kground"). Value) <> "" then...
OR Len it:
If Len(Trim(Country.Fields.It em("Countr yBackgroun d").Value) ) > 0 then...
see if those work
If Trim(Country.Fields.Item("
OR Len it:
If Len(Trim(Country.Fields.It
see if those work
ASKER
apresto:
the response write displays the paragraphs in the memo field, but the if then statement displays nothing...the memo field contains "’s" and other html
Is this why?
the response write displays the paragraphs in the memo field, but the if then statement displays nothing...the memo field contains "’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.It em("Countr yBackgroun d").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("Count ryBackgrou nd").Value )
Response.write "LEN = " & Len(trim(Country.Fields.It
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("Count
ASKER
LEN = 1524
Server.HTMLencode does not work
Server.HTMLencode does not work
what about
<% if len(Country.Fields.Item("C ountryBack ground").V alue) > 0 then %>
<%=(Country.Fields.Item("C ountryBack ground").V alue)%>
<% end if %>
see if this helps you
<% if len(Country.Fields.Item("C
<%=(Country.Fields.Item("C
<% end if %>
see if this helps you
sorry, @apresto write my solution first
ASKER
seems like the len statement should work but it does not
what about
<% if not (isnull(Country.Fields.Ite m("Country Background ").Value) or isempty(Country.Fields.Ite m("Country Background ").Value)) then %>
<%=(Country.Fields.Item("C ountryBack ground").V alue)%>
<% end if %>
<% if not (isnull(Country.Fields.Ite
<%=(Country.Fields.Item("C
<% 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)
@John_Lennon - No worries :o)
ASKER
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.Ite m("Country Background ").Value) or isempty(Country.Fields.Ite m("Country Background ").Value)) then %>
<%=(Country.Fields.Item("C ountryBack ground").V alue)%>
<% end if %>
<p><span class="style25"><%=(Countr y.Fields.I tem("Count ryBackgrou nd").Value )%></span> </P>
<% if not (isnull(Country.Fields.Ite
<%=(Country.Fields.Item("C
<% end if %>
<p><span class="style25"><%=(Countr
try ....
<%
tmp=Country.Fields.Item("C ountryBack ground").V alue
if tmp<>"" then
Response.Write tmp
end if
%>
<%
tmp=Country.Fields.Item("C
if tmp<>"" then
Response.Write tmp
end if
%>
try this
strTemp = Country.Fields.Item("Count ryBackgrou nd").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
strTemp = Country.Fields.Item("Count
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
ASKER
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("C ountryBack ground").V alue
if tmp<>"" then %>
<%=(Country.Fields.Item("C ountryName ").Value)% >
<%end if
%>
I lose the value
guess I'll have to use response.write
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("C
if tmp<>"" then %>
<%=(Country.Fields.Item("C
<%end if
%>
I lose the value
guess I'll have to use response.write
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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("C ountryBack ground").V alue
if tmp<>"" then %>
<%=Country.Fields.Item("Co untryName" ).Value%>
<%end if
%>
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("C
if tmp<>"" then %>
<%=Country.Fields.Item("Co
<%end if
%>
Response.Write "Field = " & Country.Fields.Item("Count
if (Country.Fields.Item("Coun
Response.write (Country.Fields.Item("Coun
end if
%>
What is printed to the screen if you run this? Field = ....