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 4 of 4
  1. #1
    New Coder
    Join Date
    May 2010
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Reponse.write if statement

    Hi
    I'm trying to display "Download" if a file exists, however I cannot figure out how to wrap the if statement + response.write.

    Can someone help thanks



    Code:
    <% if OnInvoice("Filenameuploaded")>0 Then response.write "/dev_invoiceregister/uploads/"&OnInvoice("Filenameuploaded")& "'>download</a> "%></td>

  • #2
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    this is the correct syntax, but I still dont think it will work because the output of OnInvoice("Filenameuploaded") is not clear

    I ask because at first you are comparing it as a number, but when building the link, you are using it as a string.


    Code:
    <% if OnInvoice("Filenameuploaded") >0 Then
     response.write "<a='/dev_invoiceregister/uploads/"&OnInvoice("Filenameuploaded")& "'>download</a>
     "%></td>
    Last edited by DanInMa; 10-28-2011 at 08:46 PM. Reason: removed extra qoute

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,536
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    Oops, Dan! You have a bogus extra apostrophe in there.

    The one in /uploads/'" needs to be zapped.

    Also, coding it like this might be clearer/easier:
    Code:
    <td>
    <% if OnInvoice("Filenameuploaded") >0 Then %>
        <a="/dev_invoiceregister/uploads/<%=OnInvoice("Filenameuploaded")%>">download</a>
    <% End If %>
    </td>
    I agree that sure comparing > 0 is likely wrong. Maybe it should be
    Code:
    <% if OnInvoice("Filenameuploaded") <> "" Then %>
    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.

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    whoops, ty sir. also good point, I forget you can do it that way sometimes, and it's so much easier to format your html that way too.


  •  

    Posting Permissions

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