Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML JavaScript

PHP problem with all browsers except IE

Javascript coding ..

Moderators: macek, egami, gesf

PHP problem with all browsers except IE

Postby scooterp83 » Mon May 10, 2004 11:11 pm

I have a ad rotator script that i need help with. It works fine in internet explorer but when i go to my site with any other browser like mozilla or opera the images dont show because it says there is a javascript error: here is my code and here is my error. I REALLY NEED TO FIX THIS FOR MY JOB. CAN SOMEONE PLEASE HELP ME!!!!

Code: Select all
<?PHP
// Functions:

// Gives today's date with no time
function todaysDate()
{
   list($dd,$mm,$yyyy) = split("-",date("d-m-Y",time()));
   return makeDateValue($dd,$mm,$yyyy);
}

function makeDateValue($dd,$mm,$yyyy)
{
   return mktime(0, 0, 0, $mm, $dd, $yyyy);
}


?>
<SCRIPT LANGUAGE="JavaScript">
// Setup
var curAd;
var ads = new Array();
var delays = new Array();
var linx = new Array();
var external = new Array();
function displayAd()
{
   var adLink = document.getElementById("ADLINK");
   var ad = document.getElementById("AD");
   if (ads.length)
   {   
      ad.src = "./Ads/"+ads[curAd];         !!!!!!!THIS IS THE ERROR LINE
      adLink.href=linx[curAd];
      if (external[curAd])
      {
         adLink.target="_blank";
      }
      else
      {
         // It's one of our own!
         adLink.target="_self";
      }
      if (ads.length > 1)
         // Skip refresh if we only have 1 ad!
         setTimeout("displayAd()",delays[curAd]*1000);
      // Move on
      curAd = (++curAd) % ads.length;
   }
}
</SCRIPT>

<DIV align=center>
<A id=ADLINK href="#">
<IMG id=AD border=0 src="#">
</A>

<SCRIPT LANGUAGE="JavaScript">
// Setup
var i = 0;

// PHP generated JavaScript array:
<?php
$fd = fopen ("./Ads/ads.csv", "r");
if ($fd)
{
   $adsUsed = 0;
   $today = todaysDate();
   $line = null;
   while (!feof ($fd))
   {
      if (!$line)
      {
         // Skip header
         $line = fgets($fd, 4096);
      }
      else
      {
         $line = fgets($fd, 4096);
         if (strlen($line) > 10)
         {
            list($startDate,$durationMonths,$adDurationSecs,$pipeSeparatedImages,$URL) = split (",", $line, 5);
            list($dd,$mm,$yyyy)= split ("\/", $startDate, 3);
            $startDateTime = mktime(0, 0, 0, $mm, $dd, $yyyy);
            $endDateTime = mktime(0, 0, 0, $mm + $durationMonths, $dd, $yyyy);
            if ($durationMonths < 0 || ($durationMonths > 0 && ($startDateTime <= $today ) && ($today <= $endDateTime)))
            {
               // We've got a contender
               ++$adsUsed;
               $image = split("\|",$pipeSeparatedImages);
               foreach($image as $anImage)
               {
                  if (strtolower(substr($URL,0,7))=="http://")
                  {
                     echo "external[i]=true;\n";
                  }
                  echo "ads[i] = \"$anImage\";\n";
                  echo "linx[i] = \"".rtrim($URL)."\";\n";
                  echo "delays[i++] = $adDurationSecs;\n";
               }
            }
         }
      }
   }
   fclose($fd);
}
?>
// Prevent same start ad being shown on every new page.. add random element
curAd = <?php echo rand(0,$adsUsed - 1); ?>;
displayAd();
</SCRIPT>
</DIV>


The error i get is:

Error: ad has no properties
Source File: http://www.hiphopnext.com/Ads.php
Line: 14


Line 14 is:
ad.src = "./Ads/"+ads[curAd];

[/code]

I REALLY NEED HELP

MY HTML PAGE HAS A IFRAME like the following:

Code: Select all
 <iframe name="ADS" src="Ads.php" scrolling="no" frameborder="0"
                    height="60" width="468" align="center" marginheight="0" marginwidth="0"></iframe>
scooterp83
New php-forum User
New php-forum User
 
Posts: 3
Joined: Mon May 10, 2004 11:02 pm

Postby gesf » Thu May 13, 2004 10:06 pm

I really don´t know, but it must be some code/browser incompatibility!
Anyway, i think a good start is refering to the elements hierarchically!
You better do it... like:
Code: Select all
// This:
window.document.ad.src

// Instead of:
ads.src

Who knows... maybe this is the problem!
Try it ;)
User avatar
gesf
Moderator
Moderator
 
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

Postby scooterp83 » Fri May 14, 2004 3:34 pm

thanks alot for the reply that code still give me and error saying it has no properties. ANy ideas?
scooterp83
New php-forum User
New php-forum User
 
Posts: 3
Joined: Mon May 10, 2004 11:02 pm

Postby gesf » Fri May 14, 2004 6:21 pm

I really don´t know!
There are time, mainly when using frames, we have to use the window Object, but in this case we can omit it!

So use it starting with document property, like:
Code: Select all
// This:
document.ad.src

// Instead of:
ads.src
// or...
window.document.ad.src

Anyway, make sure you´re using that when refering to every Element!
User avatar
gesf
Moderator
Moderator
 
Posts: 1717
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden

view source

Postby ruturajv » Sun May 16, 2004 7:53 pm

I think... I dont know, you are trying to access the ads array before it is being populated...

please check if its happening.. try to put the function of changing images after populateing the array
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India

Postby scooterp83 » Thu Jun 03, 2004 6:51 am

no that didnt work any other ideas
scooterp83
New php-forum User
New php-forum User
 
Posts: 3
Joined: Mon May 10, 2004 11:02 pm

Postby ruturajv » Thu Jun 03, 2004 8:06 pm

Code: Select all
<DIV align=center>
<A id=ADLINK href="#">
<IMG id=AD border=0 src="#">
</A>



try this first...
Code: Select all
<DIV align=center>
<A id="ADLINK" href="#">
<IMG id="AD" border="0" src="#">
</A>


and in Mozilla... !
open the javascript console by typing "javascript:" in the URL
you'll get a much better understanding of the problem.
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India


Return to JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron