...

View Full Version : Same 2 JS in same page



williega
06-12-2008, 08:09 AM
Greetings,

I followed the directions on this link and could not get my 2 js to work on the same page. http://www.javascriptkit.com/javatutors/multiplejava.shtml

I took out the 2 body tags and combined them like this:
<BODY onLoad="SLIDES.update(); SLIDES.update()">....and nothing

I have the same exact JS but I want 2 instances running on the same page with different images (links). These are the 2. How do I get them to work on the same page?

Script 1:
--------------------
<SCRIPT TYPE="text/javascript" SRC="../js/slideshow.js">
</SCRIPT>
<SCRIPT TYPE="text/javascript">
<!--
SLIDES = new slideshow("SLIDES");

s = new slide();
s.src = "../images/dining.jpg";
s.link = "dining.htlm";
s.target = "_blank";
SLIDES.add_slide(s);

s = new slide();
s.src = "../images/dining1.jpg";
s.link = "dining.html";
s.target = "_blank";
SLIDES.add_slide(s);

s = new slide();
s.src = "../images/dining2.jpg";
s.link = "dining.html";
s.target = "_blank";
SLIDES.add_slide(s);

s = new slide();
s.src = "../images/dining3.jpg";
s.link = "dining.html";
s.target = "_blank";
SLIDES.add_slide(s);
//-->
</SCRIPT>



<BODY onLoad="SLIDES.update()"><A HREF="javascript:SLIDES.hotlink()">
<IMG NAME="SLIDESIMG" SRC="../images/dining1.jpg" ALT="Go To Sponsor" STYLE="width:144px;height:216px;filter:progid:DXImageTransform.Microsoft.Fade()"></A>

<SCRIPT type="text/javascript">
<!--
document.write("<UL>\n");
document.write(SLIDES.get_all_text("<li>", "\n"));
document.write("<" + "/UL>");
//-->
</SCRIPT>
<SCRIPT TYPE="text/javascript">
<!--
if (document.images)
{
SLIDES.set_image(document.images.SLIDESIMG);
SLIDES.set_textid("SLIDESTEXT"); // optional
SLIDES.update();
SLIDES.play(); //optional
}
//-->

</SCRIPT>
--------------------
Script 2:

<SCRIPT TYPE="text/javascript" SRC="../js/slideshow.js">
</SCRIPT>

<SCRIPT TYPE="text/javascript">
<!--
SLIDES = new slideshow("SLIDES");

s = new slide();
s.src = "../images/photo1.jpg";
s.link = "dining.htlm";
s.target = "_blank";
SLIDES.add_slide(s);

s = new slide();
s.src = "../images/photo2.jpg";
s.link = "dining.html";
s.target = "_blank";
SLIDES.add_slide(s);

s = new slide();
s.src = "../images/photo3.jpg";
s.link = "dining.html";
s.target = "_blank";
SLIDES.add_slide(s);

s = new slide();
s.src = "../images/photo1.jpg";
s.link = "dining.html";
s.target = "_blank";
SLIDES.add_slide(s);
//-->
</SCRIPT>

<BODY onLoad="SLIDES.update()"><A HREF="javascript:SLIDES.hotlink()"><img name="SLIDESIMG" src="../images/photo1.jpg" alt="Go To Sponsor" style="width:144px;height:216px;filter:progid:DXImageTransform.Microsoft.Fade()" /></A>

<SCRIPT type="text/javascript">
<!--
document.write("<UL>\n");
document.write(SLIDES.get_all_text("<li>", "\n"));
document.write("<" + "/UL>");
//-->
</SCRIPT>
<SCRIPT TYPE="text/javascript">
<!--
if (document.images)
{
SLIDES.set_image(document.images.SLIDESIMG);
SLIDES.set_textid("SLIDESTEXT"); // optional
SLIDES.update();
SLIDES.play(); //optional
}
//-->

</SCRIPT>
----------------
thank you
Willie

Philip M
06-12-2008, 08:38 AM
Please format code in your posts using the CODE tag!

You cannnot simply have two instances of the same script running on the same page.

The names of functions and variables must not be duplicated, as otherwise the second simply overwrites the first.

The only solution is to rename all the functions and variables in the second script, e.g.

SLIDES2 = new slideshow("SLIDES2");

s2 = new slide();
s2.src = "../images/photo1.jpg";
s2.link = "dining.htlm";
s2.target = "_blank";
SLIDES2.add_slide(s2);

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum