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 10 of 10
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    9
    Thanks
    7
    Thanked 0 Times in 0 Posts

    2 Column Ad Randomizer in ASP

    I posted an issue with a java script randomizer in the javascript forum and member "Old Pedant" recommended writing the code in ASP rather than javascript.

    The website is www.VillageOfManito.com/template.asp

    I have removed the randomizer for the time being and replaced with static "includes"

    I need the ads to randomize with each page load. The format continues throughout the website.

    "Old Pedant" said the coding would be very easy, but my ASP knowledge is limited and I am starting from scratch here.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,986
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    So the include files are still left_column.htm and right_column.htm?

    Hmmm...yeah, must be, because you still have multiple <body> tags in there.

    You really shouldn't #include files that are complete HTML pages in their own right. The #include is okay, but then the stuff the you include should be designed to fit properly into the existing page(s).

    So you say you have this on every page in the site?

    And your basic structure of the part of the page where these go is this, right? And it will be the same on every page?
    Code:
    <div align="center">
        <table>
            <tr>
                <td>....the leftside ads go here ...</td>
                <td>[spacer only]</td>
                <td>...the main content goes here...</td>
                <td>[spacer only]</td>
                <td>...the rightside ads go here...</td>
            </tr>
       </table>
    </div>
    I just want to be sure this is going to be consistent on all pages.

    Off to dinner right now...back in a while.
    Last edited by Old Pedant; 12-12-2011 at 12:54 AM.
    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:

    rightbrainer (12-13-2011)

  • #3
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    9
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Smile

    Yes, that will be the format of all interior pages, plus the header which is also an include.

    One other caveat - some of the ads will have hyperlinks, others will not. An example of one of the hyperlinks is www.Subway.com for the Subway ad. If you show how to do one with a link and how to do one without, I can fill in the blanks.

    And, I do like your idea of reversing the order of the ads in the right column.

    I'm sure you've figured this out, but the object is to get all advertisers equal time "above the fold" (an old newspaper term, I was in newspapers before I retired)

    This help is definately "above and beyond the call of duty" and I am extremely grateful.

  • #4
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    9
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Be sure to give yourself and the website credit for the code in the source

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,986
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    Give what website credit? codingforums? I'm not associated with them in any way. Don't worry about it.

    Okay, here's a demo page to show that it works:
    Code:
    <html>
    <head>
    <style type="text/css">
    ul.sideAds {
        list-style-type: none;
    }
    ul.sideAds li a {
        text-decoration: none;
    }
    ul.sideAds li a img {
        border: none;
    }
    </style>
    </head>
    <body>
    <table border="0" width="1024">
    <tr>
        <td bgcolor="white" width="155" valign="top">
    <!-- #include file="manitoAds.asp" -->
        </td>
        <td background="http://www.villageofmanito.com/images/newBG.jpg" width="6"></td>
        <td bgcolor="white" width="702" valign="top">
              main content goes here
        </td>
        <td background="http://www.villageofmanito.com/images/newBG.jpg" width="6"></td>
        <td bgcolor="white" width="155" valign="top">
    <!-- #include file="manitoAds.asp" -->
        </td>
    </tr>
    </table>
    </body>
    </html>
    You should recognize the part starting with <table> and ending with </table>.

    I added the <style> section so that you can easily adjust appearances, but it's pretty much what you have now.

    Then here is the ASP file that you will #include the two places shown in the code above.

    You can, of course, change the name of the file if you also change the two #include's. Nobody but you will ever know what the name is.

    Code:
    <p style="text-align: center; color: red; font-size: small;">
        Please patronize these<br/>fine businesses that<br/>help support this site
    </p>
    <%
    ads = Array( _
      "Manito_Foods.jpg$$http://vips.food.officelive.com/$$Manito Foods", _
      "countrygen.jpg$$#$$County General", _
      "hopedale.jpg$$http://www.hopedalemedicalcomplex.com/index.htm$$Hopedale Medical Complex", _
      "democrat.jpg$$http://www.masoncountydemocrat.com/$$Mason County Democrat", _
      "willetts_ad.jpg$$http://www.willettswinery.com/$$Willetts Winery", _
      "Immaculate_Conception_ad.jpg$$#$$Immaculate_Conception", _
      "Lee-ad.jpg$$http://www.leeprintandad.com$$Lee Printing and Advertising", _
      "ad2.jpg$$mailto:rightbraincreative@gmail.com$$Advertise Her", _
      "Just_Like_Home_ad.jpg$$#$$Just Like Home Cafe", _
      "Shop_Manito_AD.jpg$$#$$Shop Manito First", _
      "subway_ad.jpg$$http://www.subway.com/$$Subway", _
      "great-clips.jpg$$http://www.greatclips.com/$$Great Clips", _
      "Chamber_Ad.jpg$$#$$Chamber of Commerce", _
      "Nickerson.jpg$$#$$Nickerson Insurance Agency LLC", _
      "meadowlawn.jpg$$#$$Meadowlawn Apartments" _
      )
    
    If Not IsArray(randomAds) Then
        Randomize
        ReDim randomAds(UBound(ads))
        For n = UBound(ads) To 0 Step -1
            pick = Int( Rnd() * (n+1) )
            randomAds(n) = ads(pick)
            ads(pick) = ads(n)
        Next
        direction = 1
    End If
    
    Response.Write "<ul class=""sideAds"">" & vbNewLine
    For n = 0 To UBound(randomAds)
        If direction = 1 Then pick = n Else pick = UBound(randomAds) - n
        parts = Split(randomAds(pick),"$$")
        If parts(1) = "#" Then ns=" onclick=""return false;"" " Else ns = ""
    %>
        <li><a href="<%=parts(1)%>" <%=ns%> target="_blank"><img src="http://www.villageofmanito.com/images/<%=parts(0)%>" 
               title="<%=parts(2)%>" alt="<%=parts(2)%>"></a></li>
    <%
    Next
    Response.Write "</ul>" & vbNewLine
    direction = -direction
    %>
    You will notice that each element in the ads array has three parts, separated by $$. The $$ is arbitrary, just picked to avoid conflict with any other content. You could change it, but you almost surely won't need to.

    Anyway, the three parts are
    imagename$$website url$$title
    If the advertiser doesn't have a website, just use # as the url.

    In the <a> links, if the website has no URL, I drop in a tiny bit of javascript code to suppress the click on that link. If a user has javascript turned off, it won't hurt. Just that then the page will reload. Big deal.

    Just so you can see it working, I put it up on one of my "junk" sites:
    http://www.plopon.com/manitoDemo.asp

    Hit refresh and, as you can see, the order of the ads changes. And, yes, the ones on the right side are in reverse order of the ones on the left.

    You can of course play around with the <style>s some more as you wish.
    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:

    rightbrainer (12-12-2011)

  • #6
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    9
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Thank you again, Old Pedant. The code works fine.

    One small issue, although the coding says align=center, the ads seem to be flush right.

    Is it because of the following code snippett
    Code:
    ul.sideAds {
        list-style-type: none;
    where list-type would normally contain a bullet or number, I am left with a space instead?

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,986
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    We could try playing with <ul> and/or <li> styles, but...

    Why don't we try killing the <li>? I just used that because it was in your template.asp, after the JS ran.

    Try these revisions. Notice that I changed the <td>'s that the ads drop into to <th>'s.
    That means they are automatically centered and the font is bolded. Notice the other <style> changes.

    If you change the <table> to border="1" (just for test purposes) you can see that it's now laying things out properly.

    *** file: manitoDemo.asp ***
    Code:
    <html>
    <head>
    <style type="text/css">
    th.manitoAds {
        background-color: white;
        width: 155px;
        vertical-align: top;
        font-size: medium;
        color: red;
    }
    th.manitoAds a {
        text-decoration: none;
    }
    th.manitoAds a img {
        border: none;
    }
    </style>
    </head>
    <body>
    <table border="0" width="1024">
    <tr>
        <th class="manitoAds">
    <!-- #include file="manitoAds.asp" -->
        </th>
        <td background="http://www.villageofmanito.com/images/newBG.jpg" width="6"></td>
        <td bgcolor="white" width="702" valign="top">
              main content goes here
        </td>
        <td background="http://www.villageofmanito.com/images/newBG.jpg" width="6"></td>
        <th class="manitoAds">
    <!-- #include file="manitoAds.asp" -->
        </th>
    </tr>
    </table>
    </body>
    </html>
    *** file: manitoAds.asp ***
    Code:
    Please patronize these<br/>
    fine businesses that<br/>
    help support this site
    <br/>
    <%
    ads = Array( _
      "Manito_Foods.jpg$$http://vips.food.officelive.com/$$Manito Foods", _
      "countrygen.jpg$$#$$County General", _
      "hopedale.jpg$$http://www.hopedalemedicalcomplex.com/index.htm$$Hopedale Medical Complex", _
      "democrat.jpg$$http://www.masoncountydemocrat.com/$$Mason County Democrat", _
      "willetts_ad.jpg$$http://www.willettswinery.com/$$Willetts Winery", _
      "Immaculate_Conception_ad.jpg$$#$$Immaculate_Conception", _
      "Lee-ad.jpg$$http://www.leeprintandad.com$$Lee Printing and Advertising", _
      "ad2.jpg$$mailto:rightbraincreative@gmail.com$$Advertise Her", _
      "Just_Like_Home_ad.jpg$$#$$Just Like Home Cafe", _
      "Shop_Manito_AD.jpg$$#$$Shop Manito First", _
      "subway_ad.jpg$$http://www.subway.com/$$Subway", _
      "great-clips.jpg$$http://www.greatclips.com/$$Great Clips", _
      "Chamber_Ad.jpg$$#$$Chamber of Commerce", _
      "Nickerson.jpg$$#$$Nickerson Insurance Agency LLC", _
      "meadowlawn.jpg$$#$$Meadowlawn Apartments" _
      )
    
    If Not IsArray(randomAds) Then
        Randomize
        ReDim randomAds(UBound(ads))
        For n = UBound(ads) To 0 Step -1
            pick = Int( Rnd() * (n+1) )
            randomAds(n) = ads(pick)
            ads(pick) = ads(n)
        Next
        direction = 1
    End If
    
    For n = 0 To UBound(randomAds)
        If direction = 1 Then pick = n Else pick = UBound(randomAds) - n
        parts = Split(randomAds(pick),"$$")
        If parts(1) = "#" Then ns=" onclick=""return false;"" " Else ns = ""
    %>
        <a href="<%=parts(1)%>" <%=ns%> target="_blank"><img src="http://www.villageofmanito.com/images/<%=parts(0)%>" 
               title="<%=parts(2)%>" alt="<%=parts(2)%>"></a><br/>
    <%
    Next
    direction = -direction
    %>
    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:

    rightbrainer (12-13-2011)

  • #8
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    9
    Thanks
    7
    Thanked 0 Times in 0 Posts
    I hope I haven't reached the point where I am a pest yet. I implemented your new code and the ads are still flush right and now there are bullet points.

    can you do something like "align=center-6px"?

  • #9
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,986
    Thanks
    79
    Thanked 4,432 Times in 4,397 Posts
    If there are bullet points, you didn't get all my new code right.

    There is no <ul> or <li> in my new code.

    Look:
    http://www.plopon.com/manitoDemo.asp

    If you are still seeing bullet points after playing with it again, can you show it live? Give a temp url?
    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:

    rightbrainer (12-12-2011)

  • #10
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    9
    Thanks
    7
    Thanked 0 Times in 0 Posts
    I found the issue... I had the include file named wrong and was still calling in a bad file.

    Works great now. Sorry for the last post, that was my error.

    Thanks for everything. You are truly an asset to this forum and to "right brainers" like me.
    Last edited by rightbrainer; 12-12-2011 at 10:50 PM. Reason: Finalized


  •  

    Posting Permissions

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