View Full Version : Dynamic image code problems - how do i?
mattboy_slim
06-16-2005, 04:43 AM
I have a the filename of an image stored in a field in a database. When attempting to show the image, I'm not getting the correct results. I want to show an alternate image or text if the field is blank, so when doing a response.write, I cannot get the image to show, but if I do it outside of an if/then/else statement, then it works fine.
Here is my code: <% if isnull(rs_featuredboats.Fields.Item("f_picture1")) then response.write("No Image") Else response.write("<img src='" & "_images/boatphotos/" & "(rs_featuredboats.Fields.Item('f_picture1').Value)'>") end if %>
Here is the output code:<img src='_images/boatphotos/(rs_featuredboats.Fields.Item('f_picture1').Value)'>
Thanks in advance for the help,
Matt
glenngv
06-16-2005, 01:08 PM
Remove the double quotes around last rs_featuredboats part.
And you don't have to put End If statement if the If...Else statement is a one-liner.
<% if isnull(rs_featuredboats.Fields.Item("f_picture1")) then response.write("No Image") Else response.write("<img src=""" & "_images/boatphotos/" & rs_featuredboats.Fields.Item('f_picture1').Value & """ />") %>
mattboy_slim
06-16-2005, 03:42 PM
Thanks, but now I get a syntax error
Microsoft VBScript compilation error '800a03ea'
Syntax error
if isnull(rs_featuredboats.Fields.Item("f_picture1")) then response.write("No Image") Else response.write("<img src=""" & "_images/boatphotos/" & rs_featuredboats.Fields.Item('f_picture1').Value & """ />")
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------^
<% if isnull(rs_featuredboats.Fields.Item("f_picture1")) then response.write("No Image") Else response.write("<img src=""" & "_images/boatphotos/" & rs_featuredboats.Fields.Item('f_picture1').Value & """ />") %>
Thanks again,
Matt
EDIT: Sorry, figured it out. I needed to put double-quotes around the "f_picture1"
Thanks,
Matt
glenngv
06-17-2005, 03:36 AM
Didn't notice it also when I posted my suggestion.
You need to use double quotes in Vbscript strings. Unlike in Javascript where single and double quotes are interchangeable.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.