PDA

View Full Version : DHTML Slide Show Script - KeepTrack & Parameter Passing



Rockeiro
07-31-2006, 06:53 AM
1) Script Title: DHTML Slide Show Script

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex14/dhtmlslide.htm

3) Describe problem:

When you look a this code, there is an unused function:
function keeptrack(){
window.status="Image "+(which+1)+" of "+photos.length
}

I added a 3rd cell between the Previous and Next links and successfully got this to print: Image 1 of 20
by adding the code:
<script>
document.write("Image "+(which+1)+" of "+photos.length)
</script>
I thought it should be easier than this but the code:
document.write(window.status) yeilds an error and the code:
document.write(+window.status) will only show a 0 where "Image 1 of 20" should be.

I thought according to the already defined keeptrack() that window.status should be a string variable so I can't figure out why this won't work using any 3 of the above methods.

As well, as you click the previous or next buttons, the first number in "Image 1 of 20" will not change. I guess this indicates that variable "which" is staying at zero, yet that doesn't make sense or the script wouldn't work at all. I've tried declaring a new variable "var whichlast=0" and passing whichlast=which at various points in the "backwards()" and "forward()" functions to try and freeze the count but this doesn't work either. I'm basically out of ideas and can't seem to get the microsoft script editor to show me these variables in a watch window nor to step through line by line so I can catch it.

I also tried unsucessfuly to try and pass a parameter from the thumbnails on my photo page to this routine so that it will start on the picture that you clicked on. Again it seemed to boil down to the "which" variable that I could not modify it's value with the modified statement:
var which=Request.QueryString("p");

I would suspect that this keeptrack function never worked or that something in the example code is missing that would make it possible to do all these things but I'm out of time for the night so I throw it out to you folks for some feedback.

Steve

jscheuer1
07-31-2006, 09:16 AM
To begin with:


function keeptrack(){
window.status="Image "+(which+1)+" of "+photos.length
}

Isn't exactly unused. However, it was written at a time when javascript could routinely rely upon being able to write to the status bar of the browser. This is pretty much no longer the case though, except in IE and some other browsers, but only if these other browsers are configured to allow it.

So, window.status isn't exactly a string that you can read and write. If you write to it but can't, when you go to read it later, it will be something other than you tried to write to it, if it is anything at all.

It gets worse, you cannot document.write() to a page once it has been parsed by the browser without overwriting all of its content. So, this type of thing:


<script>
document.write("Image "+(which+1)+" of "+photos.length)
</script>
I thought it should be easier than this but the code:
document.write(window.status) yeilds an error and the code:
document.write(+window.status) will only show a 0 where "Image 1 of 20" should be.

. . . all in all, not a very good idea.

You could hard code a span on the page, put it anywhere you like, make it look like so:


<span id="imagecount"></span>

Then modify that useless old keeptrack() function to look like so:


function keeptrack(){
var countspan=document.getElementById? document.getElementById('imagecount') : document.all['imagecount'];
countspan.innerHTML="Image "+(which+1)+" of "+photos.length;
}