PDA

View Full Version : Problem with an image src swapping scripting.



canto iv
07-06-2006, 01:33 AM
Hello there,

I am using a script to display my business's portfolio. The intent is for potentual clients to view examples of our work in an easy, hassle free manner. As you'll see when you take a look at the page so far, the 1, 2, 3, etc links work as intended but the next and back scripts aren't working. The problem seems rather simple to fix but I'm not too terrible familiar with javascript so I'm not recognizing the error.

Any help is greatly appreciated.

Website: http://www.wesruvalcaba.com/occhi/index6.htm

Twey
07-06-2006, 02:04 AM
Doesn't work at all in FX1.5.0.4.

canto iv
07-06-2006, 02:13 AM
Doesn't work at all in FX1.5.0.4.

That's what I'm using as well. Only "1" and "2" work right now. I've not added anymore content, otherwise, 3 - 15 would be functioning correctly as well. Regardless, the next and back commands aren't working properly. I've been messing with this script for the past half an hour even after posting this thread and I can't seem to get it to work. Ugh, frustration. :(

tim.thelion
07-06-2006, 04:22 AM
only one and 2 work in ie7.

canto iv
07-06-2006, 08:16 PM
Still need help. Buuuuuuuuuuuump.

Twey
07-06-2006, 08:45 PM
Frankly, I'm amazed that works at all. Also, it's considerably overcomplicated.
<script type="text/javascript">
Number.prototype.toDigits(n, r) {
var s = this.toString(r ? r : 10);
while(s.length < n)
s = "0" + s;
return s;
}

var count = 1,
MyImages = new Array();
for(var i = 1; i <= 15; ++i)
(MyImages[i] = new Image()).src = "examples/page" + i.toDigits(2) + ".jpg";

function loadImg(elName, img) {
var imgNum = parseInt(img);
if(!isNaN(imgNum)) document.images[elName].src = MyImages[count = imgNum].src;
else
for(var i = 0; i < MyImages.length; ++i)
if(MyImages[i].src == img) {
count = i;
document.images[elName].src = img;
break;
}
}

function imgNext() {
if (count < MyImages.length - 1) loadImg(++count);
else loadImg(count = 1);
}

function imgBack() {
if (count > 1) loadImg(--count);
else loadImg(count = MyImages.length - 1);
}
</script>

<!-- ... stuff ... -->

<a class="pglink">|&lt;</a><a class="pglink" href="javascript:imgBack()">&lt;</a>
<a class="pglink" href="examples/page01.jpg" onclick="loadimg('workImage', this.href); return false;">1</a>
<!-- ... et cetera ... -->
<a class="pglink" href="javascript:imgNext()">&gt;</a>

canto iv
07-06-2006, 11:19 PM
Frankly, I'm amazed that works at all. Also, it's considerably overcomplicated.

Thanks. It doesn't seem to work properly, though. Rather than swapping the image src, it redirects to just the image src alone when you click on 1 - 15. Back and next commands don't work a all either.

Twey
07-06-2006, 11:21 PM
Demo?

canto iv
07-07-2006, 06:54 PM
Demo?

http://www.wesruvalcaba.com/occhi/index7.html

Twey
07-07-2006, 07:10 PM
Ah, my error.
Number.prototype.toDigits = function(n, r) {
var s = this.toString(r ? r : 10);
while(s.length < n)
s = "0" + s;
return s;
}