Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Location
    Leicester
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.

  • Users who have thanked Old Pedant for this post:

    jimbo83 (11-29-2011)

  • #3
    New to the CF scene
    Join Date
    Nov 2011
    Location
    Leicester
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.

  • #5
    New to the CF scene
    Join Date
    Nov 2011
    Location
    Leicester
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.

  • #7
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,062
    Thanks
    4
    Thanked 8 Times in 8 Posts
    also You want to only have single quotes in the Request.querystring

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

    Use Request.QueryString("room1downstairsname")

  • #8
    New to the CF scene
    Join Date
    Nov 2011
    Location
    Leicester
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •