Solved

If Then Else Statement to Randomly Show 2 Ads

Posted on 2008-06-09
1
759 Views
Last Modified: 2013-12-25
I have on page on a site I am working on that is a PHP page.  At the top it has an ad spot that is rotating 2 different ads.  It is working by coming up with a random number, then depending on whether it is even or odd, it displays one of the two ads.

Here is the php code:

<? if(rand(0,10)<5){ ?>
  <script type="text/javascript">
      google_ad_client = "pub-29xxxxxxxx";
      google_ad_width = 120;
      google_ad_height = 600;
      google_ad_format = "120x600_as";
      google_ad_type = "text_image";
      google_ad_channel ="6xxxxxxxxx";
      google_color_bg = "353269";
      google_color_link = "FFFFFF";
      google_color_text = "e0e0e0";
      google_color_url = "b8b8b8";
</script>
  <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
  <? }else{ ?>
  <a href="http://www.someadsite.com" target="_blank"><img src="http://www.somewebsite.com/images/web-ad-someadsite.jpg" width="120" height="620" border="0" /></a>
  <? } ?>

I need to pull off something like this, but on a standard .html page.  Is there a way to do this using javascript or straight html?
0
Comment
Question by:TheShaner
[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
1 Comment
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 21749412
Like this
  <script type="text/javascript">
if (Math.floor(Math.random()*2) ==0) { 
      google_ad_client = "pub-29xxxxxxxx";
      google_ad_width = 120;
      google_ad_height = 600;
      google_ad_format = "120x600_as";
      google_ad_type = "text_image";
      google_ad_channel ="6xxxxxxxxx";
      google_color_bg = "353269";
      google_color_link = "FFFFFF";
      google_color_text = "e0e0e0";
      google_color_url = "b8b8b8";
    document.write('<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"><\/script>');
  }else{ 
      document.write('<a href="http://www.someadsite.com" target="_blank"><img src="http://www.somewebsite.com/images/web-ad-someadsite.jpg" width="120" height="620" border="0" /></a>');
  }
</script>

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to dynamically set the form action using jQuery.

738 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