...

View Full Version : problem with image gallery script - stops at 10th image



mike_11
06-04-2005, 01:18 PM
Hi I've been trying to use a bit of script posted on a forum for a simple image gallery with back/next buttons and thumbnails. Looks great and nearly works, but have played and searched and cant for the life of me work out why it wont work after image 10. Theres also a small problem with the first thumbnail not working normally. Can anyone help?

The original script was this
http://misc.nickbrokeit.net/devshed/polo_o/

and this is my best effort so far (script pasted below)
http://www.mikesteel.co.uk/new/folio10.htm

Really appreciate any help, once i can crack this I'll be able to finish redoing my site (www.mikesteel.co.uk) - ive already got the front done with some useful javascript:
http://www.mikesteel.co.uk/new/new.htm

thanks + have a great weekend
Mike



<script type="text/JavaScript">
function showPic(p)
{
var m=document.getElementById('mainPic');
var p=document.getElementById('pic'+p);
for (var i=1; i<=18; i++) document.getElementById('pic'+i).border="1";
p.border="1";
m.src=p.src;
m.name=p.id;
}
function showPrev()
{
var m=document.getElementById('mainPic');
var current=m.name.charAt(3)*1;
var next=(current==1)?18:current-1;
m.src="image"+next+".jpg";
m.name="pic"+next;
for (var i=1; i<=18; i++) document.getElementById('pic'+i).border="1";
document.getElementById('pic'+next).border="1";
}
function showNext()
{
var m=document.getElementById('mainPic');
var current=m.name.charAt(3)*1;
var next=(current==18)?1:current+1;
m.src="image"+next+".jpg";
m.name="pic"+next;
for (var i=1; i<=18; i++) document.getElementById('pic'+i).border="1";
document.getElementById('pic'+next).border="1";
}
</script>

canadianjameson
06-04-2005, 04:59 PM
if it goes through 9 images and fails on the tenth, one of two things is happening (imo)

either there is a slight problem with image #10 itself... easily testible by changing the image it loads and seeing if it still fails... or theres something wrong in the script whereby the number 10 is causing a prob (unlikely)

toss the code for your images and we'll be able to reproduce the problem

canadianjameson
06-04-2005, 05:06 PM
i take that back, the problem isnt with the pic.

it seems that any pic over the # of 9 doesnt work with the previous / forward buttons.

what about a number with more that one digit would cause these functions to fail?



function showPrev()
{
var m=document.getElementById('mainPic');
var current=m.name.charAt(3)*1;
var next=(current==1)?18:current-1;
m.src="image"+next+".jpg";
m.name="pic"+next;
for (var i=1; i<=18; i++) document.getElementById('pic'+i).border="1";
document.getElementById('pic'+next).border="1";
}
function showNext()
{
var m=document.getElementById('mainPic');
var current=m.name.charAt(3)*1;
var next=(current==18)?1:current+1;
m.src="image"+next+".jpg";
m.name="pic"+next;
for (var i=1; i<=18; i++) document.getElementById('pic'+i).border="1";
document.getElementById('pic'+next).border="1";
}

canadianjameson
06-04-2005, 05:11 PM
i see it now:


var next=(current==1)?18:current-1

you have 18 images... everytime you go up by 1, :current-1 goes down by 1!

18 - 9 = 9, and the script fails because it gets two 9's (if next = 9 but current = 9... what do you do.

a quick workaround might be to either remove or add an image (lemme know)

mike_11
06-06-2005, 07:15 PM
hey thanks - I've kept trying and finally got it to work :)

canadianjameson
06-06-2005, 07:44 PM
what fixed it?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum