dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: Image Array help

Hybrid View

  1. #1
    Join Date
    May 2010
    Posts
    2

    Unhappy Image Array help

    For a homework assignment I need to create a page that uses javascript to allow you to click a button to replace one image with another. I need to use atleast 3 images to display on screen.

    I found what seems like a great tutorial on how to do it here http://www.irt.org/articles/js132/index.htm but because I am very very new to javascript I do not understand where to fill in MY information and what information stays as part of the code. For example where it has this:

    <script language="JavaScript"><!--which_image_loaded = 0;

    function changeImage(direction) {
    which_image_loaded += direction;
    if (which_image_loaded < 0)
    which_image_loaded = 19; //Again, one less than the actual number of images.
    if (which_image_loaded > 19)
    which_image_loaded = 0;
    if (document.images)
    document.myimage.src = ImageNames[which_image_loaded];
    }
    //--></script>

    Can someone tell me which sections I am supposed to edit to fill in with my information? For example I know that I change 19 because this tutorial is for 20 images and I only need 3 so I know that I would use 2 because it starts counting at 0. But where it says which_image_loaded am I supposed to put a file name there or is that part of the javascript? and where it says "document.myimage.src = ImageNames[which_image_loaded]; is myimage.src part of the javascript? I am so confused please help me!!!

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    filename = ("image" + file_number + ".jpg");
    Your images should be named "image1.jpg", "image2.jpg", etc.


    document.myimage.src = ImageNames[which_image_loaded];
    This is the name of the image to be changed
    <img alt="" name="myimage" src="image1.jpg" height="100" width="100">

  3. #3
    Join Date
    May 2010
    Posts
    2
    thank you very much for responding but I am still confused. Would you show me what it would literally look like if my images were "image1.jpg" and "image2.jpg"?

  4. #4
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    It's a homework assignment; you must try yourself.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles