slideshow and variable name for images (global?)

Discussion in 'Javascript' started by drillbit_99@yahoo.com, Sep 25, 2005.

  1. Guest

    I have an HTML page of thumbnail images. Each image can begin a
    slideshow of the images on the page by clicking on the image. This
    opens another HTML page that begins the slideshow using large images of
    the thumbnails. When the slideshow begins it always starts with the
    first image. I would like to pass the name of the thumbnail to the
    slideshow HTML page and begin the slideshow with the same image the
    user clicks on. Is this asking too much? Does anyone have a solution?


    -----------------------------------------------------------------
    ---------thumbnail page
    -----------------------------------------------------------------
    -----------------------------------------------------------------
    -----------------------------------------------------------------


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title>DHS Homecoming 2005</title>
    <meta http-equiv="content-type" content="text/html;
    charset=iso-8859-1">
    <link rel=stylesheet type="text/css" href="styles.css">
    </head>

    <body>
    <h1 class=title>Homecoming 2005</h1>

    <p class=desc>Munson Stadium, Forest Park - September 23,
    2005<br><br>Click on any photo to see an enlarged version.
    </p>

    <br>

    <center>
    <table cellspacing="12">
    <tr>
    <td class=thumbnail width="192" height="192">
    <a href="pictures/slides.html" name="dsc_0021"><img
    src="thumbs/DSC00067.jpg" width="192" height="131" border="0"
    alt="DSC00067.jpg"></a>
    </td>
    <td class=thumbnail width="192" height="192">
    <a href="pictures/slides.html" name="dsc_0018"><img
    src="thumbs/DSC00068.jpg" width="192" height="131" border="0"
    alt="DSC00068.jpg"></a>
    </td>
    <td class=thumbnail width="192" height="192">
    <a href="pictures/slides.html" name="dsc_0020"><img
    src="thumbs/DSC00069.jpg" width="192" height="131" border="0"
    alt="DSC00069.jpg"></a>
    </td>
    </tr>
    <tr>
    <td class=thumbnail width="192" height="192">
    <a href="pictures/slides.html" name="dsc_0022"><img
    src="thumbs/DSC00070.jpg" width="192" height="131" border="0"
    alt="DSC00070.jpg"></a>
    </td>
    <td class=thumbnail width="192" height="192">
    <a href="pictures/slides.html" name="dsc_0029"><img
    src="thumbs/DSC00071.jpg" width="192" height="131" border="0"
    alt="DSC00071.jpg"></a>
    </td>
    <td class=thumbnail width="192" height="192">
    <a href="pictures/slides.html" name="dsc_0030"><img
    src="thumbs/DSC00072.jpg" width="192" height="131" border="0"
    alt="DSC00072.jpg"></a>
    </td>
    </tr>
    <tr>
    <td class=thumbnail width="192" height="192">
    <a href="pictures/slides.html" name="dsc_0031"><img
    src="thumbs/DSC00073.jpg" width="192" height="131" border="0"
    alt="DSC00073.jpg"></a>
    </td>
    <td class=thumbnail width="192" height="192">
    <a href="pictures/slides.html" name="dsc_0033"><img
    src="thumbs/DSC00074.jpg" width="192" height="131" border="0"
    alt="DSC00074.jpg"></a>
    </td>
    <td class=thumbnail width="192" height="192">
    <a href="pictures/slides.html" name="dsc_0035"><img
    src="thumbs/DSC00075.jpg" width="192" height="131" border="0"
    alt="DSC00075.jpg"></a>
    </td>
    </tr>
    <tr>
    <td class=thumbnail width="192" height="192">
    <a href="pictures/slides.html" name="dsc_0038"><img
    src="thumbs/DSC00076.jpg" width="192" height="131" border="0"
    alt="DSC00076.jpg"></a>
    </td>
    <td class=thumbnail width="192" height="192">
    <a href="pictures/slides.html" name="dsc_0039"><img
    src="thumbs/DSC00077.jpg" width="192" height="131" border="0"
    alt="DSC00077.jpg"></a>
    </td>
    <td class=thumbnail width="192" height="192">
    <a href="pictures/slides.html" name="dsc_0040"><img
    src="thumbs/DSC00078.jpg" width="192" height="131" border="0"
    alt="DSC00078.jpg"></a>
    </td>
    </tr>
    <tr>
    <td class=thumbnail width="192" height="192">
    <a href="pictures/slides.html" name="dsc_0041"><img
    src="thumbs/DSC00079.jpg" width="192" height="131" border="0"
    alt="DSC00079.jpg"></a>
    </td>
    <td class=thumbnail width="192" height="192">
    <a href="pictures/slides.html" name="dsc_0046"><img
    src="thumbs/DSC00080.jpg" width="192" height="131" border="0"
    alt="DSC00080.jpg"></a>
    </td>

    </tr>
    </table>
    </center>



    <br>
    <br>
    <table cellspacing="8">
    <tr>
    <td width="20" height="20"> </td>
    </tr>
    </table>


    <p class=desc>Last updated: 6/10/2005
    </p>

    </body>
    </html>


    -----------------------------------------------------------------
    ----------slideshow page
    -----------------------------------------------------------------
    -----------------------------------------------------------------
    -----------------------------------------------------------------



    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title>SOSU Marching Contest</title> <script language="JavaScript">

    <!-- Begin
    NewImg = new Array (
    "DSC00081.jpg",
    "DSC00082.jpg",
    "DSC00083.jpg",
    "DSC00084.jpg",
    "DSC00085.jpg",
    "DSC00086.jpg",
    "DSC00087.jpg",
    "DSC00088.jpg",
    "DSC00089.jpg",
    "DSC00090.jpg",
    "DSC00091.jpg",
    "DSC00092.jpg"
    );
    var ImgNum = 0;
    var ImgLength = NewImg.length - 1;


    var delay = 3000;

    var lock = false;
    var run;
    function chgImg(direction) {
    if (document.images) {
    ImgNum = ImgNum + direction;
    if (ImgNum > ImgLength) {
    ImgNum = 0;
    }
    if (ImgNum < 0) {
    ImgNum = ImgLength;
    }
    document.slideshow.src = NewImg[ImgNum];
    }
    }
    function auto() {
    if (lock == true) {
    lock = false;
    window.clearInterval(run);
    }
    else if (lock == false) {
    lock = true;
    run = setInterval("chgImg(1)", delay);
    }
    }
    </script>
    <link rel="stylesheet" type="text/css" href="../styles.css">
    </head>
    <body>
    <img src="DSC00081.jpg" name="slideshow" width="850">
    <table border="10" frame="box" width="850" bgcolor="#FFCC33">
    <tr>
    <td align="center" width="100">
    <a href="javascript:chgImg(-1)">Previous</a>
    </td>
    <td align="center">
    <a href="javascript:auto()">Auto/Stop</a>
    </td>
    <td align="center" width="100">
    <a href="javascript:chgImg(1)">Next</a>
    </td>
    </tr>
    </table>
    </body>
    </html>
    , Sep 25, 2005
    #1
    1. Advertising

  2. ASM Guest

    a écrit :
    > I have an HTML page of thumbnail images. Each image can begin a
    > slideshow of the images on the page by clicking on the image. This
    > opens another HTML page that begins the slideshow using large images of
    > the thumbnails. When the slideshow begins it always starts with the
    > first image. I would like to pass the name of the thumbnail to the
    > slideshow HTML page and begin the slideshow with the same image the
    > user clicks on. Is this asking too much? Does anyone have a solution?


    I'll expect functions of slideshow work

    ----slideshow page----

    [JS part]

    funcion getImg() {
    newImg = self.location.search.substring(1)
    auto(newImg);
    }

    function auto(nbrImg) {
    nbrImg = (nbrImg && nbrImg!='') nbrImg : 1;
    if (lock == true) {
    lock = false;
    window.clearInterval(run);
    }
    else if (lock == false) {
    lock = true;
    run = setInterval("chgImg("+nbrImg+")", delay);
    }
    }

    [HTML part]

    <body onload="getImg()">

    ----end complement slideshow----

    -----thumbnail page-----

    links this way :

    <a href="pictures/slides.html?67" name="dsc_0021"><img
    src="thumbs/DSC00067.jpg" width="192" height="131" border="0"
    alt="thumbnail" title="click me to get me in a slideshow"></a>

    add number of image to load at end of href
    don't forget the '?'
    href="file.htm?number"



    --
    Stephane Moriaux et son [moins] vieux Mac
    ASM, Sep 25, 2005
    #2
    1. Advertising

  3. Guest

    I added the function "getImg" to the slideshow page and replaced the
    function "auto" with your script. I also replaced the "body" tag.

    I changed my link on the thumbnail page and made sure I kept the '?'.

    When I tried the code, a click on the second picture link (using '?68')
    it performed as if nothing had changed. The link still opens the first
    picture in the slideshow.

    Should the '?' variable be 'DSC00068.jpg'? I tried that also and
    nothing changed.
    , Sep 25, 2005
    #3
  4. ASM Guest

    a écrit :
    > I added the function "getImg" to the slideshow page and replaced the
    > function "auto" with your script. I also replaced the "body" tag.
    >
    > I changed my link on the thumbnail page and made sure I kept the '?'.
    >
    > When I tried the code, a click on the second picture link (using '?68')
    > it performed as if nothing had changed. The link still opens the first
    > picture in the slideshow.
    >
    > Should the '?' variable be 'DSC00068.jpg'? I tried that also and
    > nothing changed.
    >

    an error in a function ?
    (a '?' forgoten)

    try this :

    function auto(nbrImg) {
    nbrImg = (nbrImg && nbrImg!='')? nbrImg : 1;
    if (lock == true) {
    lock = false;
    window.clearInterval(run);
    }
    else if (lock == false) {
    lock = true;
    run = setInterval("chgImg("+nbrImg+")", delay);
    }
    }

    --
    Stephane Moriaux et son [moins] vieux Mac
    ASM, Sep 25, 2005
    #4
  5. ASM Guest

    a écrit :
    > I added the function "getImg" to the slideshow page and replaced the
    > function "auto" with your script. I also replaced the "body" tag.
    >
    > I changed my link on the thumbnail page and made sure I kept the '?'.
    >
    > When I tried the code, a click on the second picture link (using '?68')


    68 have to be the index of array corresponding
    to photo to start with

    that's to say i.e. "DSC00085.jpg" in your example :
    link -> href="pictures/slides.html?4"

    > it performed as if nothing had changed. The link still opens the first
    > picture in the slideshow.
    >
    > Should the '?' variable be 'DSC00068.jpg'? I tried that also and
    > nothing changed.


    sorry, some misunderstanding with your original script
    hope this time it will be ok

    ----slideshow page----

    [JS part]

    // new function to start on correct image
    funcion getImg() {
    ImgNum = self.location.search.substring(1);
    // alert to verify if that's ok (to delete after tests)
    alert('image number : '+ImgNum);
    lock == false;
    chgImg(1);
    auto();
    }

    // re-insert old function auto()
    // and of course all complete old script you did have
    function auto() {
    nbrImg = (nbrImg && nbrImg!='') nbrImg : 1;
    if (lock == true) {
    lock = false;
    window.clearInterval(run);
    }
    else if (lock == false) {
    lock = true;
    run = setInterval("chgImg(1)", delay);
    }
    }

    <body onload="getImg();">

    ----- end ----

    if that runs only after some delay
    you can try without the onload in body tag
    and puting in all end of page (before </body>)
    the following :

    <script type="text/javascript">
    getImg();
    </script>


    ====== variante ======

    if you prefer a link this way :
    (real photo number)

    <a href="pictures/slides.html?0038" name="dsc_0038"><img
    src="thumbs/DSC00076.jpg" width="192" height="131" border="0"
    alt="DSC00076.jpg">

    // new function to start on correct image
    funcion getImg() {
    var startImg = self.location.search.substring(1);
    // alert to verify if that's ok (to delete after tests)
    alert('image number : '+startImg);
    for var(i=0;i<ImgLength;i++)
    if(NewImg.indexOf(startImg)>0) ImgNum=i;
    // alert to verify if that's ok (to delete after tests)
    alert('image Array index = '+ImgNum);
    lock == false;
    chgImg(1);
    auto();
    }


    --
    Stephane Moriaux et son [moins] vieux Mac
    ASM, Sep 25, 2005
    #5
  6. Guest

    Well, I'm pretty stupid with Javascript. I placed the new code in the
    slideshow page, but I don't see where the function 'getImg' is called.
    Can you tell me how to make the call? Below is the revised code for
    the slideshow page. Thanks for the help.


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title>Homecoming</title> <script language="JavaScript">
    <!-- Original: Mike Canonigo () -->
    <!-- Web Site: http://www.munkeehead.com -->

    <!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! http://javascript.internet.com -->

    <!-- Begin
    NewImg = new Array (
    "DSC00067.jpg",
    "DSC00068.jpg",
    "DSC00069.jpg",
    "DSC00070.jpg",
    "DSC00071.jpg",
    "DSC00072.jpg",
    "DSC00073.jpg",
    "DSC00074.jpg",
    "DSC00075.jpg",
    "DSC00076.jpg",
    "DSC00077.jpg",
    "DSC00078.jpg",
    "DSC00079.jpg",
    "DSC00080.jpg"
    );
    var ImgNum = 0;
    var ImgLength = NewImg.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;
    if (ImgNum > ImgLength) {
    ImgNum = 0;
    }
    if (ImgNum < 0) {
    ImgNum = ImgLength;
    }
    document.slideshow.src = NewImg[ImgNum];
    }
    }



    // new function to start on correct image
    function getImg() {
    ImgNum = self.location.search.substring(1);
    // alert to verify if that's ok (to delete after tests)
    alert('image number : '+ImgNum);
    lock == false;
    chgImg(1);
    auto();

    }

    // re-insert old function auto()
    // and of course all complete old script you did have
    function auto() {
    nbrImg = (nbrImg && nbrImg!='') nbrImg : 1;
    if (lock == true) {
    lock = false;
    window.clearInterval(run);
    }

    else if (lock == false) {
    lock = true;
    run = setInterval("chgImg(1)", delay);
    }

    }
    </script>
    <link rel="stylesheet" type="text/css" href="../styles.css">
    </head>
    <body onload="getImg();">
    <img src="DSC00067.jpg" name="slideshow" width="850">
    <table border="10" frame="box" width="850" bgcolor="#FFCC33">
    <tr>
    <td align="center" width="100">
    <a href="javascript:chgImg(-1)">Previous</a>
    </td>
    <td align="center">
    <a href="javascript:auto()">Auto/Stop</a>
    </td>
    <td align="center" width="100">
    <a href="javascript:chgImg(1)">Next</a>
    </td>
    </tr>
    </table>
    </body>
    </html>
    , Sep 25, 2005
    #6
  7. ASM Guest

    a écrit :
    > Well, I'm pretty stupid with Javascript. I placed the new code in the
    > slideshow page, but I don't see where the function 'getImg' is called.
    > Can you tell me how to make the call? Below is the revised code for
    > the slideshow page. Thanks for the help.


    ok,
    with, in other page, links with real photo number
    (I don't know if photo number would be 0038 or 0076 ?)

    <a href="pictures/slides.html?0038" name="dsc_0038"><img
    src="thumbs/DSC00076.jpg" width="192" height="131" border="0"
    alt="DSC00076.jpg"></a>

    You can also do :
    href="pictures/slides.html?DSC00070.jpg"
    if you prefer
    but take care : sensitive case (a 'D' is not a 'd')

    here is your page (tested)

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title>Homecoming</title> <script language="JavaScript">
    <!-- Original: Mike Canonigo () -->
    <!-- Web Site: http://www.munkeehead.com -->

    <!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! http://javascript.internet.com -->

    <!-- Begin
    NewImg = new Array (
    "DSC00067.jpg",
    "DSC00068.jpg",
    "DSC00069.jpg",
    "DSC00070.jpg",
    "DSC00071.jpg",
    "DSC00072.jpg",
    "DSC00073.jpg",
    "DSC00074.jpg",
    "DSC00075.jpg",
    "DSC00076.jpg",
    "DSC00077.jpg",
    "DSC00078.jpg",
    "DSC00079.jpg",
    "DSC00080.jpg"
    );
    var ImgNum = 0;
    var ImgLength = NewImg.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;
    if (ImgNum > ImgLength) {
    ImgNum = 0;
    }
    if (ImgNum < 0) {
    ImgNum = ImgLength;
    }
    document.images['slideshow'].src = NewImg[ImgNum];
    }
    }

    function auto() {
    if (lock == true) {
    lock = false;
    window.clearInterval(run);
    }
    else if (lock == false) {
    lock = true;
    run = setInterval("chgImg(1)", delay);
    }
    }

    function getImg() {
    var startImg = self.location.search.substring(1);
    for (var i=0;i<ImgLength;i++)
    if(NewImg.indexOf(startImg)>0) ImgNum = +i-1;
    lock == false;
    chgImg(1);
    auto();
    }

    </script>
    <link rel="stylesheet" type="text/css" href="../styles.css">
    <style type="text/css">
    p, button { text-align: center; }
    img { margin: auto; margin-bottom: 10px; width: 850px; }
    p.buttons { background-color: #fc3; margin: 10px; border: 1px solid black; }
    button { border: outset goldenrod 3px; background: #ff9;
    color: maroon; margin: 4px 10px; width: 100px; }
    button:hover { border-style: inset; }
    button:active { background: orange; color: white; }
    </style>
    </head>
    <body>
    <p><img src="DSC00067.jpg" name="slideshow" width="850"></p>
    <p class="buttons">
    <button onclick="delay=delay*1.2;auto();auto();">Slower</button>
    <button onclick="chgImg(-1)">Previous</button>
    <button onclick="auto()">Auto/Stop</button>
    <button onclick="chgImg(1)">Next</button>
    <button onclick="delay=delay*.8;auto();auto();">Faster</button>
    </p>
    <script type="text/javascript">
    getImg();
    </script>
    </body>
    </html>



    --
    Stephane Moriaux et son [moins] vieux Mac
    ASM, Sep 25, 2005
    #7
  8. ASM wrote:
    <snip>
    > function auto(nbrImg) {
    > nbrImg = (nbrImg && nbrImg!='') nbrImg : 1;
    > if (lock == true) {
    > lock = false;
    > window.clearInterval(run);
    > }
    > else if (lock == false) {
    > lock = true;
    > run = setInterval("chgImg("+nbrImg+")", delay);
    > }
    > }

    <snip>

    What a very bad example of programming. Beyond the omission of the
    question mark in the conditional expression, what values for - nbrImg -
    are expected to type convert to boolean true and then possibly equal the
    empty string? The possible value of - nbrImg - that will producde false
    in - nbrImg != '' - are boolean false, +/- zero and the empty string,
    all of which either are false or would type-convert to false in the
    right hand side of the logical expression.

    It is invariable unwise to perform type-converting comparison with a
    boolean value without a specific reason. The values that do equal true
    with type-converting comparison are: boolean true, the number 1 and the
    string "1". It is unusual to want to only allow this particular set of
    values to trigger the entry into a branch in an if/else statement. It is
    much more likely that the intention is that the - lock - value be
    exclusively boolean and so that requirement would be enforced with a
    strict comparison operation (===), or taken advantage of by allowing the
    internal ToBoolean call implicit in the - if - expression to react to
    the true-ness of the value, eliminating the then redundant comparison,
    and the - if - statement in the else branch. So either:-

    Only when boolean:-

    if(lock === true){ //only if boolean true
    ....
    }else if(lock === false){ //else if boolean false
    ...
    }

    -or, reacting to type-converted true-ness:-

    if(lock){ // any 'true' value including boolean true
    ...
    }else{ //else any 'false' value including boolean false
    ...
    }

    If the global - lock - variable is initialised (as it mist be for the
    original function to work at all) then it would be logical to initials
    it to boolean false, and then use the second if/else formulation where
    only boolean values are assigned to - lock -.

    Richard.
    Richard Cornford, Sep 26, 2005
    #8
  9. ASM Guest

    Richard Cornford a écrit :
    > ASM wrote:
    > <snip>
    >
    >>function auto(nbrImg) {
    >>nbrImg = (nbrImg && nbrImg!='') nbrImg : 1;
    >>if (lock == true) {
    >>lock = false;
    >>window.clearInterval(run);
    >>}
    >>else if (lock == false) {
    >>lock = true;
    >>run = setInterval("chgImg("+nbrImg+")", delay);
    >> }
    >>}

    >
    > <snip>
    >
    > What a very bad example of programming. Beyond the omission of the
    > question mark in the conditional expression,


    I've seen it too late

    > what values for - nbrImg -
    > are expected to type convert to boolean true and then possibly equal the
    > empty string? The possible value of - nbrImg - that will producde false
    > in - nbrImg != '' - are boolean false, +/- zero and the empty string,
    > all of which either are false or would type-convert to false in the
    > right hand side of the logical expression.


    I want only to know if nbrImg exists and if is not empty
    -> answer waited : false or true
    boolean or not is JS's problem.

    histories about 'look' are not mine

    you forgot to see in thread : <script language="JavaScript">

    tell all that to :
    <!-- Original: Mike Canonigo () -->
    <!-- Web Site: http://www.munkeehead.com -->
    <!-- This script and many more are available free online at -->
    <!-- The JavaScript Source!! http://javascript.internet.com -->

    as I understood this script comes
    Certainly a lot of job to correct all oldies and mal writed scripts
    is waiting a good soul.

    --
    Stephane Moriaux et son [moins] vieux Mac
    ASM, Sep 26, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mohanasundaram
    Replies:
    44
    Views:
    1,039
    Keith Thompson
    Aug 24, 2004
  2. Bobby Chamness
    Replies:
    2
    Views:
    2,378
    Joe Smith
    Apr 22, 2007
  3. Jeannie
    Replies:
    2
    Views:
    163
    Jeannie
    Apr 12, 2004
  4. Whitney
    Replies:
    2
    Views:
    104
    Whitney Cali
    Jul 26, 2004
  5. Replies:
    6
    Views:
    108
Loading...

Share This Page