Script Is Almost There

Discussion in 'Javascript' started by scorpion53061, Jul 14, 2004.

  1. I was really proud of myself. Having never worked with javascript before I
    took two scripts - one that did a slideshow but fit the image to the table
    and one that did not but provided a caption and I managed to get them
    together.

    Unfortauntely the "Previous" link returns an "undefined" error the second
    time through it. Does anyone have an idea what I might have done wrong??

    <html>

    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <script>
    var NewImg = new Array(); // don't change this
    var Caption = new Array(); // don't change this

    NewImg[7] = 'pic1.jpeg';
    NewImg[2] = 'pic2.jpeg';
    NewImg[3] = 'pic3.jpeg';
    NewImg[4] = 'pic4.jpeg';
    NewImg[5] = 'pic5.jpeg';
    NewImg[6] = 'pic6.jpeg';
    NewImg[1] = 'pic7.jpeg';
    NewImg[8] = 'newlogo.jpg';

    // Specify the Captions...
    // To add more captions, just continue
    // the pattern, adding to the array below.
    // To use fewer captions, remove lines
    // starting at the end of the Caption array.
    // Caution: The number of Captions *must*
    // equal the number of NewImgs!

    Caption[1] = "Text for picture1.";
    Caption[2] = "Text for picture2.";
    Caption[3] = "Text for picture3.";
    Caption[4] = "Text for picture4.";
    Caption[5] = "Text for picture5.";
    Caption[6] = "Text for picture6.";
    Caption[7] = "Text for picture7.";
    Caption[8] = "Text for picture8.";
    var ImgNum = 0;
    var ImgLength = NewImg.length - 1;
    var ImgCap = Caption.length - 1;
    //Time delay between Slides in milliseconds
    var delay = 3000;
    var lock = false;
    var run;
    function chgImg(direction) {
    if (document.images) {
    ImgNum = ImgNum + direction;
    ImgCap = ImgCap + direction;
    if (ImgNum > ImgLength) {
    ImgNum = 1;
    }
    if (ImgNum < 0) {
    ImgNum = ImgLength;
    }
    document.slideshow.src = NewImg[ImgNum];
    }
    if (document.getElementById)
    document.getElementById("CaptionBox").innerHTML= Caption[ImgNum];

    }
    function auto() {
    if (lock == true) {
    lock = false;
    window.clearInterval(run);
    }
    else if (lock == false) {
    lock = true;
    run = setInterval("chgImg(1)", delay);
    }}
    // End -->
    </script>

    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>New Page 1</title>
    </head>

    <body>
    <body onload='showHot=true;self.focus();'">

    <table border="1" id="table1 " width="30%">
    <tr>
    <td id=CaptionBox class=Caption align=center colspan="3">
    Welcome to Sand Bay Beach Resorts!!<br>Designed By
    <a href="http://www.kjmsolutions.com ">KJM Solutions</a></td>
    </td>
    </tr>

    <td colspan="3"><!--webbot bot="HTMLMarkup " startspan --><img
    src="http://newlogo.jpg " name="slideshow"> //this line causes error on
    slideshow but //putting a space after the w and before the " seemed to make
    it go away. I know dumb idea right :)?
    <tr/>
    <td width="50 "><a href="javascript:chgImg(1) ">Next</a></td>

    <td width = "50 "><a href="javascript:chgImg(-1) ">Previous</a></td>

    <td width = "50 "><a href="javascript:auto() ">Auto/Stop</a></td>

    </tr>

    </table>
    <!--webbot bot="HTMLMarkup " endspan i-checksum="26346" --></td>
    </tr>
    </table>

    <p>&nbsp;</p>

    </body>

    </html>
     
    scorpion53061, Jul 14, 2004
    #1
    1. Advertisements

  2. scorpion53061

    Jimmy Cerra Guest

    Welcome to the wild world of JavaScript, Scorpion 53061!
    Did you know that this can be replaced by:

    NewImg = [
    'pic7.jpeg',
    'pic2.jpeg',
    'pic3.jpeg',
    'pic4.jpeg',
    'pic5.jpeg',
    'pic6.jpeg',
    'pic1.jpeg',
    'newlogo.jpg'
    ];

    Saves some typing (and precious bandwidth).
    I'll leave the debugging to others; however, I will point out that
    your HTML is invalid. Fix it, then put your script into an external
    file (for maximum efficiency).

    Here's a hint, though. You probably have a "race condition" causing
    the error. Type wrapping everything into a function, and call it
    during the onload event.

    Hope that's useful,
     
    Jimmy Cerra, Jul 15, 2004
    #2
    1. Advertisements

  3. No, see
    <http://validator.w3.org/check?uri=h...andbaybeach/standardsuites.asp&ss=1;verbose=1>

    If I change the encoding to ISO-8859-1 so that the document can be
    validated, the Validator shows a bunch of errors you have *not* fixed.
    And if you would have not top-posted as strongly recommended in the
    FAQ, you would have probably known: <http://jibbering.com/faq/#FAQ2_3>


    PointedEars
     
    Thomas 'PointedEars' Lahn, Jul 18, 2004
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.