Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Same 2 JS in same page

    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/javatut...iplejava.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;filterrogidXImageTransform.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;filterrogidXImageTransform.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

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,983
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    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.
    Last edited by Philip M; 06-12-2008 at 08:17 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •