...

View Full Version : multiple scripts wont work one .js file and reg script



plantsrus
12-17-2007, 05:06 AM
I am new to javascripts and have read many help files on this but cannot fix problem. Both work by thier self but not together. web site to view code www.guntersgreenhouse.com/newhome1207 and .js file i am linking to is

var bannerImg = new Array();
// Enter the names of the images below
bannerImg[0]="abfgImages/mb1sm.jpg";
bannerImg[1]="abfgImages/mb2sm.jpg";
bannerImg[2]="abfgImages/mp3sm.jpg";
bannerImg[3]="abfgImages/mp4sm.jpg";

var newBanner = 0;
var totalBan = bannerImg.length;

function cycleBan() {
newBanner++;
if (newBanner == totalBan) {
newBanner = 0;
}
document.banner.src=bannerImg[newBanner];
// set the time below for length of image display
// i.e., "4*1000" is 4 seconds
setTimeout("cycleBan()", 4*1000);
}
window.onload=cycleBan;

any help with this would be appriciated thanks.:confused:

Philip M
12-17-2007, 08:24 AM
This topic has been covered very many times. Your problem is that you have more than one onload statement and the second over-writes the first.

For the solution see:-

http://www.javascriptkit.com/javatutors/multiplejava.shtml

plantsrus
12-17-2007, 01:59 PM
I do understand that but I have read many many help topics and have tried everything but nothing works my .js script will not work no matter what I try I have even tried not using .js and put reg script in and both in body on load and will not work will you take a quick look and see if I am overlooking something Thanks.

<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="banner.js"></script>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_displayStatusMsg(msgStr) { //v1.0
status=msgStr;
document.MM_returnValue = true;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>

</head>

<body onload="MM_displayStatusMsg('Buy Direct from the Grower and SAVE!!!!!');return document.MM_returnValue;MM_preloadImages('button/toptextbar_r2_c14_f2.gif','button/toptextbar_r2_c16_f2.gif','button/toptextbar_r2_c18_f2.gif','button/toptextbar_r3_c2_f2.gif','button/toptextbar_r3_c4_f2.gif','button/toptextbar_r3_c6_f2.gif','button/toptextbar_r3_c8_f2.gif','button/toptextbar_r3_c10_f2.gif','button/toptextbar_r3_c12_f2.gif','abfgImages/navbarside1_r2_c1_f2.gif','abfgImages/buttemp_f2.gif','abfgImages/navbarside1_r6_c1_f2.gif','abfgImages/navbarside1_r8_c1_f2.gif','abfgImages/navbarside1_r10_c1_f2.gif','abfgImages/navbarside1_r12_c1_f2.gif','abfgImages/navbarside1_r14_c1_f2.gif','abfgImages/navbarside1_r16_c1_f2.gif','abfgImages/navbarside1_r18_c1_f2.gif')">
<div align="center">

my banner.js script uses windows on load in script
window.onload=cycleBan;

I have tried to put that in the body on load ;cycleban() could it be because the b in cycleban is not in caps.
Thanks for any help.

Philip M
12-17-2007, 02:08 PM
Try this:-

<body onload="cycleBan(); MM_displayStatusMsg('Buy Direct from the Grower and SAVE!!!!!');return document.MM_returnValue;MM_preloadImages('button/toptextbar_r2_c14_f2.gif','button/toptextbar_r2_c16_f2.gif','button/toptextbar_r2_c18_f2.gif','button/toptextbar_r3_c2_f2.gif','button/toptextbar_r3_c4_f2.gif','button/toptextbar_r3_c6_f2.gif','button/toptextbar_r3_c8_f2.gif','button/toptextbar_r3_c10_f2.gif','button/toptextbar_r3_c12_f2.gif','abfgImages/navbarside1_r2_c1_f2.gif','abfgImages/buttemp_f2.gif','abfgImages/navbarside1_r6_c1_f2.gif','abfgImages/navbarside1_r8_c1_f2.gif','abfgImages/navbarside1_r10_c1_f2.gif','abfgImages/navbarside1_r12_c1_f2.gif','abfgImages/navbarside1_r14_c1_f2.gif','abfgImages/navbarside1_r16_c1_f2.gif','abfgImages/navbarside1_r18_c1_f2.gif')">
<div align="center">

and of course remove the line window.onload=cycleBan; from your .js file.

Javascript is case sensitive, and cycleban is not the same as cycleBan.

plantsrus
12-17-2007, 02:16 PM
That works perfect I just noticed the b in cycleban was in caps this morning I have been dealing with this for a week sorry I had to bug you I cant believe I missed that before Thank you very very much.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum