I want to use 2 varibles in my javascript wich I set in this piece of code:
Code:
<script language="JavaScript">
var prev=1;
var next=2;
</script>
in the following function I want to re-set these variables..
But how can I use the new values in my site?..
The alert is to show the values in the function are right.
Code:
function slideFolio(col){
var prev = col-1;
var next = col+1;
alert(prev + ' - ' + next);
}
And this is part of my site where I use these 2 snippets
I want to use 2 varibles in my javascript wich I set in this piece of code:
Code:
<script language="JavaScript">
var prev=1;
var next=2;
</script>
in the following function I want to re-set these variables..
But how can I use the new values in my site?..
The alert is to show the values in the function are right.
Code:
function slideFolio(col){
var prev = col-1;
var next = col+1;
alert(prev + ' - ' + next);
}
And this is part of my site where I use these 2 snippets
I am trying to understand what your reference to 'next' and 'prev' mean.
You are changing two different variables ("next' and 'prev').
Eventually 'prev' will become a negative number.
And 'next' can go on to infinity.
How you are using these two variables together escapes me.
Logic would tend to indicate that 'next' and 'prev', increment or decrement a single variable that is probably used as an object pointer.
Say for instance you are trying to create a Slide Show of images or documents or pages.
And you want to change them by clicking a 'next' or 'prev' button.
I would do something like this:
This script uses an array to hold image file names.
It could easily be adopted to use document file names.
Or different page files.
HTML Code:
<script language="JavaScript">
// Replace the image file names in this array with your image file names.//
var slideImages = new Array("image1.jpg","image2.jpg","image3.jpg","image4.jpg","image5.jpg","image6.jpg","image7.jpg","image8.jpg","image9.jpg","image10.jpg");
var current = 0; // Set to first slideImages value.
var slide; // Used by setInterval().
function slideFolio(col){
if(col == "prev"){current-=1;} // Decerement the current slide number.
if(col == "next"){current+=1;} // Increment the current slide number.
if(current < 0){current = slideImages.length-1;} // This rolls the slide number from first to last.
if(current == slideImages.length){current = 0;} // This rolls the slide number from last to first.
var obj = document.getElementById("slide_image"); // Get the 'image object'.
obj.src = slideImages[current]; // Assign the slideImages value to the 'image object' src property.
obj.alt = slideImages[current]; // Assign the slideImages value to the 'image object' alt property.
}
function startShow()
{
stopShow();
current = -1;
slide = setInterval("slideFolio('next')", 2000); // This interval is set for 2 seconds between images (1000 = 1 second). //
}
function stopShow()
{
if(slide){clearInterval(slide);} // This clears the interval if one is started and stops the slide show.
}
</script><table><tr><td colspan="2" align="center"><img id="slide_image" src="image1.jpg" alt="image1.jpg" /></td></tr><tr><td align="right"><button id="button_left" onclick="slideFolio('prev');">Prev</button></td><td><button id="button_right" onclick="slideFolio('next');">Next</button></td></tr><tr><td><button id="button_right" onclick="startShow();">Start Slide Show</button></td><td><button id="button_right" onclick="stopShow();">Stop Slide Show</button></td></tr></table>