Well, the dang thing works.
Hard to believe it was that easy. Yeah, I had it incrementing just
forgot to send it along too.
Thanks very much Van.
Regards,
Chuck
-----Original Message-----
From: Van Knowles [mailto:vknowles@s...]
Sent: Sunday, January 12, 2003 10:46 PM
To: javascript
Subject: [javascript] Re: How to store variables to increment
First, you have to declare the variable outside the function, as in:
<script>
var iNum =3D -1;
function Next_Image() {....}
</script>
It's good practice (in my opinion) to give it an initial value (-1 in
this
case, because the array is 0-based).
Second, you need to define a value for pic[0] as well (again, because
the
array is 0-based).
And, unless I'm missing something, you're not incrementing the variable
anywhere. You need iNum++ somewhere in the function (in this example,
before using it, because it's initialized to -1).
I hope that helps.
-Van
> Hello,
I'm trying to set a button to scroll through images, but the variable
keeps starting at 0 after each button click, it won't increment. How can
I have the variable store so that it's value will advance to the next
increment? =3D20 Here's part of the code and how I'm trying to do it.
<script language=3D3D"JavaScript">
function Next_Image()
{
var iNum;
pic =3D3D new Array(2);
=3D20
pic[1] =3D3D "pic01.jpg";
pic[2] =3D3D "pic02.jpg";
=3D20
imgField.src =3D3D "images/" + pic[iNum];
};
</script>
=3D20
<html>
<input type=3D3D"button" value=3D3D"Next Picture -->"
onClick=3D3D"Next_Image()">
</html>
=3D20
Regards,
Chuck