Solved

response.write and include file?

Posted on 2006-11-17
9
254 Views
Last Modified: 2013-11-18
Hi,

I am trying to adapt a script which was originally used to see if an image name matches a variable within a specific folder, if it does then the image is displayed, if not then a default image is displayed.  I need to do a similar thing, but this time I am displaying different (html) text.  I thought about doing it with the html text in little include asp files but I am not sure if it works with the script.  Could someone take a look for me and advise.

<%
' See if there is a brand string in var level2 and that matches a brand description

Set fs=Server.CreateObject("Scripting.FileSystemObject")

if prodrs("p_level2") <> "" then
  if fs.fileexists(server.mappath("includes/" & server.urlencode(prodrs("p_level2")) & ".asp")) then
   response.write "<!-- #INCLUDE FILE=""includes/" & server.urlencode(prodrs("p_level2")) & ".asp"">"
else
   response.write "<!-- #INCLUDE FILE=""includes/default.asp"">"
end if
else
  response.write "<!-- #INCLUDE FILE=""includes/default.asp"">"
end if

set fs=nothing
%>

Many thanks,
Tony

0
Comment
Question by:Treder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
9 Comments
 
LVL 22

Expert Comment

by:WMIF
ID: 17967884
that will not work because includes are processed by the server before the asp code is processed.  depending on what is in the pages, it may work to do something like this.  the first one wont work though because of the asp code in the include statement

<%
' See if there is a brand string in var level2 and that matches a brand description

Set fs=Server.CreateObject("Scripting.FileSystemObject")

if prodrs("p_level2") <> "" then
  if fs.fileexists(server.mappath("includes/" & server.urlencode(prodrs("p_level2")) & ".asp")) then
%>
<!-- #INCLUDE FILE=""includes/" & server.urlencode(prodrs("p_level2")) & ".asp"">  <-------  no worky
<%
else
%>
<!-- #INCLUDE FILE=""includes/default.asp"">
<%
end if
else
%>
<!-- #INCLUDE FILE=""includes/default.asp"">
<%
end if

set fs=nothing
%>
0
 

Author Comment

by:Treder
ID: 17968143
Many thanks for the reply.

Yes, I read up a bit about the include processing.  Will give it a go and report back
0
 

Author Comment

by:Treder
ID: 17970912
I guess I could do something like this:

...
if prodrs("p_level2") = "producta" then %>

<td> product a text </td>

<%
else if prodrs("p_level2") = "productb" then
%>

<td> product b text </td>

<%
else
%>

<td> default text </td>

<%
end if


Would that be sensible??
set fs=nothing
%>
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 11

Accepted Solution

by:
Dany Balian earned 500 total points
ID: 17971564
or you can do sthg like
...
select case prodrs("p_level2")

case "producta"
%>
<td> proudct a text </td>
<%
case "productb"
%>
<td> proudct b text </td>
<%
case "productc"
%>
<td> proudct c text </td>
<%
case else
%>
<td> other product text</td>
<% end select %>


or even without opening a series of <% %>

<%
Select case prodrs("p_level2")
case "producta": response.write ("<td>product a text</td>")
case "productb": response.write ("<td>product b text</td>")
case "productc": response.write ("<td>product c text</td>")
case else: response.write ("<td>other product text</td>")
end select
<%>


same goes if you want to use nested IF statements
<%
if prodrs("p_level2")="producta" then
  response.write ("<td>product a text</td>")
elseif prodrs("p_level2")="productb" then
  response.write ("<td>product b text</td>")
elseif prodrs("p_level2")="productc" then
  response.write ("<td>product c text</td>")
else
  response.write ("<td>other product text</td>")
end if
%>

hope this helps..

cheers

dan
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 17971573
please note that in your case you have one missing end if

the syntax of if statements is:

if condition then
'statement1
elseif condition2 then     'else and if are attached together no space between them
'statement2
elseif condition3 then
'statement3
else
'statement 4
end if

cheers,

dan
0
 

Author Comment

by:Treder
ID: 18485660
Dear hongjun,

Either you guys are ultra-tidy or I am a bit slack...  I have not yet had a chance to look at all the suggested solutions, which of course I need to do before I can allocate points appropriately.

I am sorry to the posters if they feel I have taken too long and I really appreciate the ideas put forward.

I will allocate points now based on a brief run through.

Many thanks all,
Tony
0
 

Author Comment

by:Treder
ID: 18485692
Sorry - that will teach me... In my haste I thought this was the cleanup of a newer post.  

... please ignore my previous post.
0

Featured Post

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question