Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

random ad banner "null or not an object" problem

Status
Not open for further replies.

flipside1212

Technical User
Jun 24, 2003
4
CA
Hey, I adapted a bad rotator script to diplay random ads and it works for the most part. But every so often it gets the error....

"'BannerAdImages[...].src' is null or not an object"

Every image in the array has shown up so it's not a problem with naming syntax, and the problem happens rarely, and on different images so i think it's something to do with the random statement. Anyways, here's the code, I'd be really happy if someone could help me out!

<script language=&quot;JavaScript 1.2&quot;><!--
//JavaScript Banner Ad Rotator version 2.1 - last modified 16 November 2000
//Obtained from
//User defined variables - change these variables to alter the behaviour of the script
var ImageFolder = &quot;ads&quot;; //Folder name containing the images
var ImageFileNames = new Array('ad1_beatstreet_small.jpg', 'ad2_zionsgate_small.jpg', 'ad3_brina_small.jpg',

'ad4_metro3106_small.jpg', 'ad5_eightzero_small.jpg', 'ad6_dadabase_small.jpg', 'ad7_karmajeans_small.jpg',

'ad9_blueskies_small.jpg', 'ad10_bcalhoun_small.jpg'); //List of images to use
var ImageURLs = new Array(' ' '
' ' ' '
' ' //List of hyperlinks associated with the

list of images
var DefaultURL = ' //Default hyperlink for the Banner Ad
var DisplayInterval = 7; //Number of seconds to wait before the next image is displayed
var TargetFrame = &quot;&quot;; //Name of the frame to open the hyperlink into

//Internal variables (do not change these unless you know what you are doing)
var IsValidBrowser = false;
var BannerAdCode = 0;
var BannerAdImages = new Array(NumberOfImages);
var DisplayInterval = DisplayInterval * 1000;
var NumberOfImages = ImageFileNames.length;

//Add a trailing forward slash to the ImageFolder variable if it does not already have one
if (ImageFolder.substr(ImageFolder.length - 1, ImageFolder.length) != &quot;/&quot; && ImageFolder != &quot;&quot;) { ImageFolder +=

&quot;/&quot;;
}

if (TargetFrame == '') {
var FramesObject = null;
} else {
var FramesObject = eval('parent.' + TargetFrame);
}

//Function runs when this page has been loaded and does the following:
//1. Determine the browser name and version (since the script will only work on Netscape 3+ and Internet Explorer

4+).
//2. Start the timer object that will periodically change the image displayed by the Banner Ad.
//3. Preload the images used by the Banner Ad rotator script
function InitialiseBannerAdRotator() {

//Determine the browser name and version
//The script will only work on Netscape 3+ and Internet Explorer 4+
var BrowserType = navigator.appName;
var BrowserVersion = parseInt(navigator.appVersion);

if (BrowserType == &quot;Netscape&quot; && (BrowserVersion >= 3)) {
IsValidBrowser = true;
}

if (BrowserType == &quot;Microsoft Internet Explorer&quot; && (BrowserVersion >= 4)) {
IsValidBrowser = true;
}

if (IsValidBrowser) {
TimerObject = setTimeout(&quot;ChangeImage()&quot;, DisplayInterval);


for (i = 0; i < NumberOfImages; i++) {
BannerAdImages = new Image();
BannerAdImages.src = ' ' + ImageFolder + ImageFileNames;
}

}

}

//Function to change the src of the Banner Ad image
function ChangeImage() {

if (IsValidBrowser) {
BannerAdCode = (Math.round((Math.random()*8)+1))
window.document.bannerad.src = BannerAdImages[BannerAdCode].src;
TimerObject = setTimeout(&quot;ChangeImage()&quot;, DisplayInterval);
}
}

//Function to redirect the browser window/frame to a new location,
//depending on which image is currently being displayed by the Banner Ad.
//If Banner Ad is being displayed on an old browser then the DefaultURL is displayed
function ChangePage() {

if (IsValidBrowser) {

if (TargetFrame != '' && (FramesObject)) {
FramesObject.location.href = ImageURLs[BannerAdCode];
} else {
window.open(ImageURLs[BannerAdCode]);
}

} else if (!IsValidBrowser) {
document.location = DefaultURL;
}

}
// --></script>


<a href=&quot;javascript:ChangePage()&quot;><img src=&quot; alt=&quot;Banner

Advertisement&quot; border=&quot;0&quot; hspace=&quot;0&quot; name=&quot;bannerad&quot; WIDTH=&quot;230&quot; HEIGHT=&quot;85&quot;></a></TD>
 
var BannerAdImages = new Array(NumberOfImages);


NumberOfImages is not declared before this. did u change the code?



Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top