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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy JavaScript !!help!!

    I am trying to use a JavaScript from http://mcfedries.com/JavaScript/ImageCycler.asp
    I read the instructions and tried to use the script but i am quite obviously doing something wrong! This is what i have got so far:

    <html>
    <head>
    </head>

    <SCRIPT LANGUAGE="JavaScript">
    <!--
    // Use the following variable to specify
    // the number of images
    var NumberOfImages = 14
    var img = new Array(14)
    // Use the following variables to specify the image names:
    img[0] = "http://friendpages.com/pages/movies/nadzamberbenson/photo1.jpg"
    img[1] = "http://friendpages.com/pages/movies/nadzamberbenson/photo2.jpg"
    img[2] = "http://friendpages.com/pages/movies/nadzamberbenson/photo3.jpg"
    img[3] = "http://friendpages.com/pages/movies/nadzamberbenson/photo4.jpg"
    img[4] = "http://friendpages.com/pages/movies/nadzamberbenson/photo5.jpg"
    img[5] = "http://friendpages.com/pages/movies/nadzamberbenson/photo6.jpg"
    img[6] = "http://friendpages.com/pages/movies/nadzamberbenson/photo7.jpg"
    img[7] = "http://friendpages.com/pages/movies/nadzamberbenson/photo8.jpg"
    img[8] = "http://friendpages.com/pages/movies/nadzamberbenson/photo9.jpg"
    img[9] = "http://friendpages.com/pages/movies/nadzamberbenson/photo10.jpg"
    img[10] ="http://friendpages.com/pages/movies/nadzamberbenson/photo11.jpg"
    img[11] ="http://friendpages.com/pages/movies/nadzamberbenson/photo12.jpg"
    img[12] ="http://friendpages.com/pages/movies/nadzamberbenson/photo13.jpg"
    img[13] ="http://friendpages.com/pages/movies/nadzamberbenson/photo14.jpg"
    img[14] ="http://friendpages.com/pages/movies/nadzamberbenson/photo15.jpg"
    var imgNumber = 0
    function NextImage()
    {
    imgNumber++
    if (imgNumber == NumberOfImages)
    imgNumber = 0
    document.images["VCRImage"].src = img[imgNumber]
    }
    function PreviousImage()
    {
    imgNumber--
    if (imgNumber < 0)
    imgNumber = NumberOfImages - 1
    document.images["VCRImage"].src = img[imgNumber]
    }
    //-->
    </SCRIPT>

    <IMG SRC="http://friendpages.com/pages/movies/nadzamberbenson/photo1.jpg" NAME="VCRImage">
    <br>
    <A HREF="javascript:PreviousImage()">
    <IMG SRC="http://mcfedries.com/JavaScript/reverse.gif" BORDER=0></A>
    <A HREF="javascript:NextImage()">
    <IMG SRC="http://mcfedries.com/JavaScript/forward.gif" BORDER=0></A>

    <body>
    </body>
    </html>

    If you have a spare moment, could you please tell me what i am doing wrong and what the correct html would be, thankyou,
    Nadine

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    Your image/link tags come before the body tag, should be inside

    Code:
    <IMG SRC="http://friendpages.com/pages/movies/nadzamberbenson/photo1.jpg" NAME="VCRImage">
    <br>
    <A HREF="javascript:PreviousImage()">
    <IMG SRC="http://mcfedries.com/JavaScript/reverse.gif" BORDER=0></A>
    <A HREF="javascript:NextImage()">
    <IMG SRC="http://mcfedries.com/JavaScript/forward.gif" BORDER=0></A>
    
    <body>
    </body>
    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    cfc
    cfc is offline
    Regular Coder
    Join Date
    Dec 2004
    Location
    Keswick, Ontario
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts
    also, the script should be somewhere in the document
    Here's the code with the fixes described by a1ien and I. I formatted the code a littile I was at it but I didn't add, remove, or change the functionality of anything

    Code:
    <html>
        <head>
            <script language="JavaScript">
            <!--
                // Use the following variable to specify
                // the number of images
                var NumberOfImages = 15
                var img = new Array(15)
                // Use the following variables to specify the image names:
                img[0] = "http://friendpages.com/pages/movies/nadzamberbenson/photo1.jpg"
                img[1] = "http://friendpages.com/pages/movies/nadzamberbenson/photo2.jpg"
                img[2] = "http://friendpages.com/pages/movies/nadzamberbenson/photo3.jpg"
                img[3] = "http://friendpages.com/pages/movies/nadzamberbenson/photo4.jpg"
                img[4] = "http://friendpages.com/pages/movies/nadzamberbenson/photo5.jpg"
                img[5] = "http://friendpages.com/pages/movies/nadzamberbenson/photo6.jpg"
                img[6] = "http://friendpages.com/pages/movies/nadzamberbenson/photo7.jpg"
                img[7] = "http://friendpages.com/pages/movies/nadzamberbenson/photo8.jpg"
                img[8] = "http://friendpages.com/pages/movies/nadzamberbenson/photo9.jpg"
                img[9] = "http://friendpages.com/pages/movies/nadzamberbenson/photo10.jpg"
                img[10] = "http://friendpages.com/pages/movies/nadzamberbenson/photo11.jpg"
                img[11] = "http://friendpages.com/pages/movies/nadzamberbenson/photo12.jpg"
                img[12] = "http://friendpages.com/pages/movies/nadzamberbenson/photo13.jpg"
                img[13] = "http://friendpages.com/pages/movies/nadzamberbenson/photo14.jpg"
                img[14] = "http://friendpages.com/pages/movies/nadzamberbenson/photo15.jpg"
                var imgNumber = 0
                function NextImage()
                {
                    imgNumber++
                    if (imgNumber == NumberOfImages)
                        imgNumber = 0
                    document.images["VCRImage"].src = img[imgNumber]
                }
                function PreviousImage()
                {
                    imgNumber--
                    if (imgNumber < 0)
                        imgNumber = NumberOfImages - 1
                    document.images["VCRImage"].src = img[imgNumber]
                }
            //-->
            </script>
        </head>
        <body>
            <img src="http://friendpages.com/pages/movies/nadzamberbenson/photo1.jpg" name="VCRImage"/>
            <br/>
            <a href="javascript:PreviousImage()">
            <img src="http://mcfedries.com/JavaScript/reverse.gif" border="0"/></a>
            <a href="javascript:NextImage()">
            <img src="http://mcfedries.com/JavaScript/forward.gif" border="0"/></a>
        </body>
    </html>
    Last edited by cfc; 01-07-2005 at 05:09 AM. Reason: fix javascript

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,075
    Thanks
    0
    Thanked 256 Times in 252 Posts
    The length of the array should be declared as 15 and not 14. Although when you set an array element outside its length will not produce an error.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    cfc
    cfc is offline
    Regular Coder
    Join Date
    Dec 2004
    Location
    Keswick, Ontario
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv
    The length of the array should be declared as 15 and not 14. Although when you set an array element outside its length will not produce an error.
    I just assumed the javascript code was fine, but I just fixed the problem you pointed out in the code I posted earlier

    lol, I just replied to a post a few hours ago about the ArrayIndexOutOfBoundsException in Java :P


  •  

    Posting Permissions

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