Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with creating a dynamic image tag

Status
Not open for further replies.

mmiram

IS-IT--Management
Feb 4, 2005
45
0
0
US
Hi all:

I am trying to create a dynamic image tag in an HTML file using ASP. I am kind of a beginner and am having issues with the code.

Here is the issue

The code is as follows:

<% If Request.QueryString("CID")="LF" And left(Request.QueryString("TID"),2)="JL" Then Response.Write("<img src=""categories/companies/longandfoster/jl/img/order/")&Response.Write(Request.QueryString("image"))&Response.Write("""alt=""front preview"" /> ")
ElseIf Request.QueryString("CID")="LF" And left(Request.QueryString("TID"),2)="OH" Then
Response.Write("<img src=""categories/companies/longandfoster/oh/img/order/")&Response.Write(Request.QueryString("image"))&Response.Write("""alt=""front preview"" /> ")
End IF
%>

The CID that is being passed to the page is LF and the TID is L001

The result that I am getting is

0001.jpg"alt="front preview" /> <img src="categories/companies/longandfoster/oh/img/order/

I want

<img src="categories/companies/longandfoster/oh/img/order/0001.jpg" alt="front preview" />

as the result.

Could you please verify the above code and let me know whats wrong.

Thanks a lot.
 
Try:
Code:
<% If Request.QueryString("CID")="LF" And left(Request.QueryString("TID"),2)="JL" Then
     Response.Write("<img src='categories/companies/longandfoster/jl/img/order/")
     Response.Write(Request.QueryString("image"))
     Response.Write("' alt='front preview' /> ")
  ElseIf Request.QueryString("CID")="LF" And left(Request.QueryString("TID"),2)="OH" Then
    Response.Write("<img src='categories/companies/longandfoster/oh/img/order/")
    Response.Write(Request.QueryString("image"))
    Response.Write("' alt='front preview' /> ")
  End IF
%>

The & operators are not needed between the Response.Write statements (and in fact are wrong) as Response.Write is not a function. All it does is write the data into the Response buffer.

Also notice the use of single quotes inside the strings. HTML is perfectly happy with single quotes around attribute values and it makes it a lot easier to see what you're doing in VB. A space was missing between the end of the url and the start of alt=



Bob Boffin
 
Try coding it as several Response.Write statements instead of attempting to concatenate the whole image tag with & .
Code:
<%
If Request.QueryString("CID") = "LF" And 
  left(Request.QueryString("TID"),2) = "JL" Then 
   
   Response.Write("<img 
   src=""categories/companies/longandfoster/jl/img/order/") 
   
   Response.Write( Request.QueryString("image") ) 
   
   Response.Write( """alt=""front preview"" /> ") 
   
ElseIf Request.QueryString("CID")="LF" And 
      left(Request.QueryString("TID"),2)="OH" Then 
   
   Response.Write("<img  
   src=""categories/companies/longandfoster/oh/img/order/") 

   Response.Write( Request.QueryString("image") ) 
   Response.Write("""alt=""front preview"" /> ")
End IF
%>

Response.Write produces a string in the output, but I am thinking it is not itself a string and therefore cannot be concatenated. I am not a VBScripter but I believe that the ampersand means concatenate.



 
Hey guys,

Sorry for the late reply but the code worked perfectly. Thanks a lot.

Ram.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top