Re: Newbie Help with loops

Thursday, November 10, 2011

i know very little if at all .js but i sure know your problem from
other languages

sorta simple conceptually once one get past the newbie stage of
staring at it

imageArray should be an array of "objects" each of which has both a
name and a content along with anything else you might want then you do
a lookup ~ usually first result of doing it that way is to try to
change the name which is also the key then you are stuck again but
what you do is just put a new object in the array with the new name
then null the previous one to keep it all clean

you are setting imageIndex = 0; if it wont fit - that is standard
array problem so see if you can find what is called a Vector as that
is common name for grow-able array

best solution for finding things is a Map ( tree map ) and you just re-
do the thing on a name change and put it back in the map and if
operation succeed then null the old one

how one would do a tree map in .js I dont even know where to start,
just google it and work on it

On Nov 10, 10:32 am, beth <eliz...@gmail.com> wrote:
> I thought I posted this, but it's not showing up so I'll try one more time:
>
> I'm trying to build a slide show that creates an array of variables
> (thumb1, thumb2, thumb3, etc) and assigns a src and a href to the
> current slide the when the thumbnail is clicked.  I have it working
> fine when I explicitly write it out, but I'm trying to build a look
> that will dynamically create the variable name, and then set the index
> the linkArray and the imageArray.  It's building it fine, the src and
> href both change, however they don't change as expected.  Basically
> i'll get thumb0 with the src for 1 and the href for some other index.
> I can't figure out what i'm doing wrong!  i'm frustrated, but I'm sure
> it's something simple I'm overlooking.  I'm pretty new to writing the
> code from scratch.
>
> here's the code i'm using, i would appreciate any help anyone could
> offer:
>
> setInterval(changeImage,3000);
>
> //set variables for main Slide show
> var currentSlide = document.getElementById("currentSlide");
> var currentLink = document.getElementById("currentLink");
>
> var imageArray =
> ["image1.JPG","image2.JPG","image3.JPG","image4.JPG"];
>
> var linkArray = ["link1.html","link2.html","link3.html","link4.html"];
>
> var imageIndex = 0;
>
> //Changes current slide automatically
> function changeImage() {
>        currentSlide.setAttribute("src",imageArray[imageIndex]);
>        imageIndex++;
>        if (imageIndex >= imageArray.length) {
>                imageIndex = 0;
>        }
>
> }
>
> //set variables for thumbnail strip
> var thumbnails = document.getElementById("thumbnails");
>
> var dynamicThumbs = document.getElementById("dynamicThumbs");
>
> var thumbnailArray = new Array();
>
> for (i=0; i<imageArray.length; i++) {
>        thumbnailArray[i] = document.createElement("img");
>        dynamicThumbs.appendChild(thumbnailArray[i]);
>        thumbnailArray[i].setAttribute("src",imageArray[i]);
>        thumbnailArray[i].setAttribute("width",100);
>        thumbnailArray[i].onclick = function(){
>                currentSlide.setAttribute("src", imageArray[i]);
>                currentSlide.setAttribute("href", linkArray[i]);
>                if (i < imageArray.length){
>                        imageIndex++;}
>                        else {
>                                imageIndex = 0;
>                        };
>        };
>
>
>
>
>
>
>
> }

--
You received this message because you are subscribed to the Google Groups "JavaScript Forum" group.
To post to this group, send email to javascript-information@googlegroups.com.
To unsubscribe from this group, send email to javascript-information+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/javascript-information?hl=en.

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Copyright © 2010 Web Design | Free Blogger Templates by Splashy Templates | Layout by Atomic Website Templates

Vida de bombeiro Recipes Informatica Humor Jokes Mensagens Curiosity Saude Video Games Animals Diario das Mensagens Eletronica Rei Jesus News Noticias da TV Artesanato Esportes Noticias Atuais Games Pets Career Religion Recreation Business Education Autos Academics Style Television Programming Motosport Humor News The Games Home Downs World News Internet Design Entertaimment Celebrities 1001 Games Doctor Pets Net Downs World Enter Jesus Mensagensr Android Rub Letras Dialogue cosmetics Genexus lasofia thebushrajr wingshock tripedes gorduravegetal dainfamia dejavu-transpersonal jsbenfica republicadasbadanas ruiherbon iranianforaryans eaystcheyl fotosdanadir Só Humor Curiosity Gifs Medical Female American Health Madeira Designer PPS Divertidas Estate Travel Estate Writing Computer Matilde Ocultos Matilde futebolcomnoticias girassol lettheworldturn topdigitalnet Bem amado enjohnny produceideas foodasticos cronicasdoimaginario downloadsdegraca compactandoletras newcuriosidades blogdoarmario arrozinhoii