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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple javascripts on page will not work

Status
Not open for further replies.

guardmom

Technical User
May 14, 2003
6
US
I am using Dreamweaver 4 and have this page attached to a template with some javascript in the button navigation area. I also wanted to put a slideshow in the editable region of the template and it will not work. I have used the slideshow script in other pages where there is only one script on the page. I have detached the page from the template and it is still not working. I have tried a fix from the javascript kit site using multiple codes. Somehow Dreamweaver is kicking it out I think. I am not sure what to do. Do I need a special javascript code when working in a template and editable region. ( I am a cut and paster.)
 
Usually when two javascript functions refuse to work on the same page, yet work fine independantly, the cause is two or more elements having the same identifier, the browser has no way of telling which is which. How about cutting and pasting the code on here so we can take a look.
 
Thank you...here is the complete page.I have tweaked the function about calling the images to go to a URL. I do not use it but leave the function in only using an empty (). <html>
<!-- #BeginTemplate &quot;/Templates/main.dwt&quot; -->
<head>
<!-- #BeginEditable &quot;doctitle&quot; -->
<script language=&quot;JavaScript1.1&quot;>
<!--

/*
JavaScript Image slideshow:
By JavaScript Kit (Over 200+ free JavaScript here!
*/

var slideimages=new Array()
var slidelinks=new Array()
function slideshowimages(){
for (i=0;i<slideshowimages.arguments.length;i++){
slideimages=new Image()
slideimages.src=slideshowimages.arguments
}
}

function slideshowlinks(){
for (i=0;i<slideshowlinks.arguments.length;i++)
slidelinks=slideshowlinks.arguments
}

function gotoshow(){
if (!window.winslide||winslide.closed)
winslide=window.open(slidelinks[whichlink])
else
winslide.location=slidelinks[whichlink]
winslide.focus()
}

//-->
</script>
<title>Rules</title>
<!-- #EndEditable -->
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<script language=&quot;JavaScript&quot;>
<!--
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a)&&x.oSrc;i++) x.src=x.oSrc;
}

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.indexOf(&quot;#&quot;)!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a;}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf(&quot;?&quot;))>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[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.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))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
</head>
<body bgcolor=&quot;#CCCCCC&quot; text=&quot;#000000&quot; link=&quot;#000099&quot; vlink=&quot;#000000&quot; onLoad=&quot;MM_preloadImages('/images/buttons/parents_over.gif','/images/buttons/photos_over.gif','/images/buttons/purpose1_over.gif','/images/buttons/depts_over.gif','/images/buttons/worker_over.gif','/images/buttons/calendar_over.gif','/images/buttons/home-over.gif')&quot;>
<table width=&quot;96%&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; bgcolor=&quot;#666666&quot; align=&quot;center&quot;>
<tr>
<td bgcolor=&quot;#FFFFFF&quot; width=&quot;51%&quot; background=&quot;/images/bckgrds/texture3.jpg&quot;>
<div align=&quot;center&quot;><img src=&quot;/images/carved_solid.jpg&quot; width=&quot;717&quot; height=&quot;63&quot;></div>
</td>
</tr>
</table>
<table width=&quot;102%&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; align=&quot;center&quot;>
<tr>
<td bgcolor=&quot;#FFFFFF&quot; background=&quot;/images/bckgrds/texture3.jpg&quot;>
<div align=&quot;left&quot;> <a href=&quot;/purpose.htm&quot; onMouseOut=&quot;MM_swapImgRestore()&quot; onMouseOver=&quot;MM_swapImage('Purpose','','/images/buttons/purpose1_over.gif',1)&quot;>&nbsp;&nbsp;<img name=&quot;Purpose&quot; border=&quot;0&quot; src=&quot;/images/buttons/purpose1_on.gif&quot; width=&quot;115&quot; height=&quot;39&quot; align=&quot;absmiddle&quot;></a><a href=&quot;/depts.htm&quot; onMouseOut=&quot;MM_swapImgRestore()&quot; onMouseOver=&quot;MM_swapImage('Departments','','/images/buttons/depts_over.gif',1)&quot;><img name=&quot;Departments&quot; border=&quot;0&quot; src=&quot;/images/buttons/depts1_on.gif&quot; width=&quot;115&quot; height=&quot;39&quot; align=&quot;absmiddle&quot;></a><a href=&quot;/workers_bio.htm&quot; onMouseOut=&quot;MM_swapImgRestore()&quot; onMouseOver=&quot;MM_swapImage('Workers','','/images/buttons/worker_over.gif',1)&quot;><img name=&quot;Workers&quot; border=&quot;0&quot; src=&quot;/images/buttons/worker1_on.gif&quot; width=&quot;115&quot; height=&quot;39&quot; align=&quot;absmiddle&quot;></a><a href=&quot;/main.htm&quot; onMouseOut=&quot;MM_swapImgRestore()&quot; onMouseOver=&quot;MM_swapImage('Main','','/images/buttons/home-over.gif',1)&quot;><img name=&quot;Main&quot; border=&quot;0&quot; src=&quot;/images/buttons/home1.gif&quot; width=&quot;115&quot; height=&quot;39&quot; align=&quot;absmiddle&quot;></a><a href=&quot;/calendar.htm&quot; onMouseOut=&quot;MM_swapImgRestore()&quot; onMouseOver=&quot;MM_swapImage('Calendar','','/images/buttons/calendar_over.gif',1)&quot;>
<img name=&quot;Calendar&quot; border=&quot;0&quot; src=&quot;/images/buttons/calendar1_on.gif&quot; width=&quot;115&quot; height=&quot;39&quot; align=&quot;absmiddle&quot;></a><a href=&quot;/photos.htm&quot; onMouseOut=&quot;MM_swapImgRestore()&quot; onMouseOver=&quot;MM_swapImage('Photos','','/images/buttons/photos_over.gif',1)&quot;><img name=&quot;Photos&quot; border=&quot;0&quot; src=&quot;/images/buttons/photos1_on.gif&quot; width=&quot;115&quot; height=&quot;39&quot; align=&quot;absmiddle&quot;></a></div>
</td>
</tr>
</table>
<!-- #BeginEditable &quot;information&quot; -->
<table width=&quot;745&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; height=&quot;40&quot;>
<tr>
<td height=&quot;45&quot;>
<div align=&quot;center&quot;>
<p><font face=&quot;Bazooka&quot; color=&quot;#000099&quot;>See the rules slideshow.<br>
It will repeat itself.</font></p>

</div>
</td>
</tr>
</table>
<div align=&quot;center&quot;><a href=&quot;javascript:gotoshow()&quot;><img src=&quot;/images/departments/rule1.gif&quot; name=&quot;slide&quot; border=0 width=300 height=375></a>
<script>
<!--

//configure the paths of the images, plus corresponding target links
slideshowimages(&quot;/images/departments/rule1.gif&quot;,&quot;/images/departments/rule2.gif&quot;,&quot;/images/departments/rule3.gif&quot;,&quot;/images/departments/rule4.gif&quot;,&quot;/images/departments/rule5.gif&quot;)
slideshowlinks()

//configure the speed of the slideshow, in miliseconds
var slideshowspeed=7000

var whichlink=0
var whichimage=0
function slideit(){
if (!document.images)
return
document.images.slide.src=slideimages[whichimage].src
whichlink=whichimage
if (whichimage<slideimages.length-1)
whichimage++
else
whichimage=0
setTimeout(&quot;slideit()&quot;,slideshowspeed)
}
slideit()

//-->
</script>
</div>
<p align=&quot;center&quot;><font face=&quot;arial&quot; size=&quot;-2&quot;>This free script provided by</font><br>
<font face=&quot;arial, helvetica&quot; size=&quot;-2&quot;><a href=&quot;Kit</a></font></p>
<!-- #EndEditable -->
</body>
<!-- #EndTemplate -->
</html>
 
A ha!!!! I have found it....DW does fight with the functions but I have a script from dynamicdrive.com that only needs to be placed in the body of the page. The functions do not collide. Hurray!
 
but each function not related to the other in a seperate <script> tag. i've found that if you have multiple functions in one <script> tag, if one doesn't work, none work.
if you put each unrelated function in a seperate script tag, all but the broken function will work fine. Good for trouble shooting too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top