Forum Moderators: open
I have added this bit of code to fix it:
<a href='<%if instr(WebAddress,"http://") = "" then response.Write("http://")%><%=(RsParent.Fields.Item("WebAddress").Value)%>' target="_blank"><%=(RsParent.Fields.Item("WebAddress").Value)%></a>
The code doesn't work properly though. For URLs with the 'http://' it adds an extra 'http://' rather than leaving it blank. For URLs missing the 'http://' I want to add one in and for URLs with the 'http://' I want to leave it blank. I've also tried an if-then-else-end if statement but the outcome is exactly the same.
Can anyone help?
[edited by: marcel at 1:24 pm (utc) on Jan. 28, 2010]
[edit reason] examplified [/edit]
address= here whatever you do to get the address
address2 = left(address),7)
if address2 = "http://" then
'
else
response.write("http://") and the rest of your code
end if
left(address),7) checks the 7 first characters of the initial address and if it's not http:// it will execute else. Give it a try.
<a href='<%if instr(WebAddress,"http://") = "" then response.Write("http://")%><%=(RsParent.Fields.Item("WebAddress").Value)%>' target="_blank"><%=(RsParent.Fields.Item("WebAddress").Value)%></a>
Are you sure the WebAddress variable has been given a value?
I think the following will work:
<a href='<%if instr(RsParent.Fields.Item("WebAddress").Value,"http://") = 0 then response.Write("http://")%><%=(RsParent.Fields.Item("WebAddress").Value)%>' target="_blank"><%=(RsParent.Fields.Item("WebAddress").Value)%></a>
<%
WebAddress = RsParent.Fields.Item("WebAddress").Value
if left(WebAddress,7)="http://" then WebAddress=mid(WebAddress,8)
response.write "<a href='http://"& WebAddress &"' target='_blank'>"& WebAddress &"</a>"
%>