0

I have it set up so that onclick (on a picure) calls the following function:

function nxtimg(country){
    document.getElementById("imgcont").src="images",country,"/",imgs[i],".jpg";
    i++;
}

When I click on the image however, accorfing to firebug, the src of the image is; "images". It should have been changed to something like:
"images/a/flag".
Where did I mess up?

5
Contributors
8
Replies
9
Views
5 Years
Discussion Span
Last Post by theHop
1

what are the commas for? plusyou have missed a forward slash on image path. this May work

function nxtimg(country){
  document.getElementById("imgcont").src="images/" + country + "/" + imgs[i] + ".jpg";
  i++;
}
0

@theHop
When I use plusses the function doesn't do anything...
Why's that?

0

try this

function nxtimg(contry){
    document.getElementById("imgcou").src = \""images/" +country +"/" + imgs[i] + ".jpg"\";
    i++;
}

but i don't realy understand your code. what is the use of imgs[i].
if the onclick is trigered and the code runs. i will be incread and then the code exit. there must be a way of passing the new value of i but into the code. if i know the meaning of imgs[i] i will be able to help you more.

0

try this

The code doesn't need the \", and there's also a typo in getElementById("img**cou**"). The OP originally used *imgcont*.

To the OP: Are you declaring i outside of the function? Otherwise i loses its value every time you exit the function, so it'll always return the same value, and you'll always get the same image. This is pretty much a more verbose way of saying what Troy III mentioned.

0

@ EvolutionFallen so the solution is to declear the i outside the function.
by the way thanks for the typo correction

0

@ EvolutionFallen so the solution is to declear the i outside the function.
by the way thanks for the typo correction

Yup! Otherwise once you exit the function's scope, i is unset.

0

@EvolutionFallen Yes. I was assuming it already was declared outside the function somewhere. Probably should've mentioned that :S

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.