Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-29-2011, 12:36 PM   PM User | #1
jimbo83
New to the CF scene

 
Join Date: Nov 2011
Location: Leicester
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
jimbo83 is an unknown quantity at this point
Using if statements to display images

Hi everyone,

I'm new to all of this and I'm trying to pick up as much as I can as I go along.

I am creating a form that will allow users to design a product online by their selections. So my apologies in advance as I dont think this will be the last post regarding this form

I have got the basics of the form on the first page sorted, on the second page I have a column to the right that will show the users progress. It lists the name the user enterered in a text field, and i have done this by using [CODE] <%= Request.QueryString("room1name") %> [CODE]

Next to the room name i want to add an image dependant on the selection the user made on the previous page. I have managed to get the form to work with text but not images.

The code i used for this is
[CODE] <% If Request.QueryString("room1protect")=1 Then response.write("Protected") Else response.write("unprotected")
%> [CODE]

For the part where the response is "protected" I want my image /images/tick.gif to be diaplayed and for "unprotected" I want my image /images/cross.gif to be displayed.

I have tried to insert the image where the text is but it causes an error and wont display the page at all.

Can anyone help me as to how I will get this to work.

Thanks in advance.
jimbo83 is offline   Reply With Quote
Old 11-29-2011, 08:38 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,227
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Code:
<%
If Request.QueryString("room1protect") = "1" Then 
    Response.Write "Protected <img src=""tick.gif""/>"
Else
    Response.Write "unprotected <img src=""cross.gif""/>"
End If
%>
Is that all you mean?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Users who have thanked Old Pedant for this post:
jimbo83 (11-29-2011)
Old 11-29-2011, 09:32 PM   PM User | #3
jimbo83
New to the CF scene

 
Join Date: Nov 2011
Location: Leicester
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
jimbo83 is an unknown quantity at this point
That is exactly what i was looking for.

Thank you so much.

Is it the double "" around the image title that has made that work?
jimbo83 is offline   Reply With Quote
Old 11-29-2011, 10:26 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,227
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Yes. When you want a " in a string in VBScript, you simply use two of them. In other languages, you might use \" inside of quotes, but VBS needs a pair of " marks to represent one embedded mark.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Old 11-30-2011, 04:00 AM   PM User | #5
jimbo83
New to the CF scene

 
Join Date: Nov 2011
Location: Leicester
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
jimbo83 is an unknown quantity at this point
OK, well I thought that made sense howver I can't for the life of me get this to work. I can manage text on its own, or i can get the response from the downstairs name part to be included individually. I can't however get the two to work together.

I thought that it should look something like below but that hasn't worked and it won't load a page again like before.

<% If Request.QueryString("room1downstairsprotect")="1" Then response.write " a detector is to be installed at a height of 2.4m in the " Request.QueryString(""room1downstairsname"") <br>
End if%>

I assume I've either added something too much or I need to add something extra into this?
jimbo83 is offline   Reply With Quote
Old 11-30-2011, 05:38 AM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,227
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Code:
<% 
If Request.QueryString("room1downstairsprotect")="1" Then
    Response.write " a detector is to be installed at a height of 2.4m in the " & Request.QueryString("room1downstairsname") & "<br/>"
End if
%>
Request.QueryString *IS* a string. So if you want to append it to another string you must use the concatenation operator, which in VBScript is the ampersand.

And <br/> is meaningless in VBScript. "<br/>" is s *STRING*, so again you use & to concatenate it to other strings.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote
Old 12-14-2011, 07:53 PM   PM User | #7
miranda
Senior Coder

 
Join Date: Dec 2002
Location: Arlington, Texas USA
Posts: 1,062
Thanks: 4
Thanked 8 Times in 8 Posts
miranda is an unknown quantity at this point
also You want to only have single quotes in the Request.querystring

So instead of Request.QueryString(""room1downstairsname"")

Use Request.QueryString("room1downstairsname")
miranda is offline   Reply With Quote
Old 02-11-2012, 12:09 PM   PM User | #8
jimbo83
New to the CF scene

 
Join Date: Nov 2011
Location: Leicester
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
jimbo83 is an unknown quantity at this point
Thanks for all the help with this. I've finally managed to finish off everything on that form and i now have it working

Although after finishing all 6 pages of the quote form, I found out that the company who host our site don't support asp so had to change it all to PHP. another quick learnning curve.
jimbo83 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:17 AM.


Advertisement
Log in to turn off these ads.