Hi,
I have searched the previous threads, tried everything I can, but to no avail. I am really a PHP programmer and am trying to get some javascript going. Hopefully you can help me!
I have a successful onclick image swap going for a photo album. Click on the thumbnail to show the image in the 'big image place'. I also want to add a 'back' and 'forward' link to move through the pics so I figured I'll just use the same sort of onclick for these.
I have added a function to the thumbnail onlick to set the variable 'slideback' (and later will also set slideforwasrd) which I will then use in my onlick for the 'back' and 'forward' links.
My thumbnail code that all seems to work fine:
$photos.= '<a onclick="changeImages(\'mainphoto\', \'/travel/images/photos/'.$path.'/'.$$img.'\');showText(\'caption\',\''.$$cap.'\',\'selected\',\''.$i.'\');setSlidetext(\''.$i.'\');">';
Code to print out the back link (right now I'm just trying to print out the number, but if I can get that going it will actually be part of an onclick just like the one above):
THIS WORKS but is not sufficient - just a test to make sure the function worked:
$photorows.= '<span id="backbutton"></span>
<span id="selected">1</span> of 20 photos ';
THIS DOESN'T WORK:
$photorows.= '<script type="text/javascript">document.write(slideback)</script>
<span id="selected">1</span> of 20 photos ';
Functions:
<SCRIPT language="JavaScript">
<!--
function newImage(arg) {
if (document.images) {
rslt = new Image();
rslt.src = arg;
return rslt;
}
}
function changeImages() {
if (document.images && (preloadFlag == true)) {
for (var i=0; i<changeImages.arguments.length; i+=2) {
document[changeImages.arguments].src = changeImages.arguments[i+1];
}
}
}
var preloadFlag = false;
function preloadImages() {
if (document.images) {
<?php echo $preload; ?>
preloadFlag = true;
}
}
var defaultText = " ";
function showText(section,txt)
{
for (var i=0; i<showText.arguments.length; i+=2) {
document.getElementById(showText.arguments).innerHTML = showText.arguments[i+1];
}
}
var slideback;
function setSlidetext(picnum)
{
if (picnum == 1)
{
document.getElementById("backbutton").innerHTML = " ";
}
if (picnum > 1)
{
slideback = picnum-1;
document.getElementById("backbutton").innerHTML = slideback; **I added this to test if the function works, it does
}
}
// -->
</SCRIPT>
So the main question I think is this: Why isn't the var slideback acting as a global?? If as a test I set slideback="test" before function setSlidetext, then it will print out as such in my back button area. The function does not change the value of it. Ugh.
Or if I can simply send the value of global var in my onlick so that I can use it in my backbutton onlick I should be golden too.
I hope this makes sense. Thanks in advance for your expertise!!!
I have searched the previous threads, tried everything I can, but to no avail. I am really a PHP programmer and am trying to get some javascript going. Hopefully you can help me!
I have a successful onclick image swap going for a photo album. Click on the thumbnail to show the image in the 'big image place'. I also want to add a 'back' and 'forward' link to move through the pics so I figured I'll just use the same sort of onclick for these.
I have added a function to the thumbnail onlick to set the variable 'slideback' (and later will also set slideforwasrd) which I will then use in my onlick for the 'back' and 'forward' links.
My thumbnail code that all seems to work fine:
$photos.= '<a onclick="changeImages(\'mainphoto\', \'/travel/images/photos/'.$path.'/'.$$img.'\');showText(\'caption\',\''.$$cap.'\',\'selected\',\''.$i.'\');setSlidetext(\''.$i.'\');">';
Code to print out the back link (right now I'm just trying to print out the number, but if I can get that going it will actually be part of an onclick just like the one above):
THIS WORKS but is not sufficient - just a test to make sure the function worked:
$photorows.= '<span id="backbutton"></span>
<span id="selected">1</span> of 20 photos ';
THIS DOESN'T WORK:
$photorows.= '<script type="text/javascript">document.write(slideback)</script>
<span id="selected">1</span> of 20 photos ';
Functions:
<SCRIPT language="JavaScript">
<!--
function newImage(arg) {
if (document.images) {
rslt = new Image();
rslt.src = arg;
return rslt;
}
}
function changeImages() {
if (document.images && (preloadFlag == true)) {
for (var i=0; i<changeImages.arguments.length; i+=2) {
document[changeImages.arguments].src = changeImages.arguments[i+1];
}
}
}
var preloadFlag = false;
function preloadImages() {
if (document.images) {
<?php echo $preload; ?>
preloadFlag = true;
}
}
var defaultText = " ";
function showText(section,txt)
{
for (var i=0; i<showText.arguments.length; i+=2) {
document.getElementById(showText.arguments).innerHTML = showText.arguments[i+1];
}
}
var slideback;
function setSlidetext(picnum)
{
if (picnum == 1)
{
document.getElementById("backbutton").innerHTML = " ";
}
if (picnum > 1)
{
slideback = picnum-1;
document.getElementById("backbutton").innerHTML = slideback; **I added this to test if the function works, it does
}
}
// -->
</SCRIPT>
So the main question I think is this: Why isn't the var slideback acting as a global?? If as a test I set slideback="test" before function setSlidetext, then it will print out as such in my back button area. The function does not change the value of it. Ugh.
Or if I can simply send the value of global var in my onlick so that I can use it in my backbutton onlick I should be golden too.
I hope this makes sense. Thanks in advance for your expertise!!!