Click to See Complete Forum and Search --> : problem with image gallery script - stops at 10th image


mike_11
06-04-2005, 07:13 AM
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 accept more than 10 images. 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>

phpnovice
06-04-2005, 07:39 AM
I did find that clicking on the first thumbnail does not work. You just have to put some alerts in there to find out what is going on. I did find that you have both a name=pic1 on one IMG tag and id=pic1 on another IMG tag. I wouldn't expect that to actually cause a problem, but ya never know until you find out just what *is* the problem. ;)

phpnovice
06-04-2005, 07:52 AM
As for going beyond 10 pictures... That is because you are doing this:

var current=m.name.charAt(3)*1;

That is picking up just the first digit from the name -- resulting in only 1-9.

mike_11
06-04-2005, 09:08 AM
I think I'm a bit out of my depth here. So can i solve this by naming all the image files image01.jpg through to imagexx.jpg, and changing

var current=m.name.charAt(3)*1;

to

var current=m.name.charAt(3)*2;

? As you can tell, I dont know my javascript - I think I'm going to have to get a book or something to properly crack this!

phpnovice
06-04-2005, 12:57 PM
No, don't rename the images. You can change this:

var current=m.name.charAt(3)*1;

to this:

var current=parseInt(m.name.substr(3),10);

mike_11
06-06-2005, 01:19 PM
so simple when you know how!
many thanks, really appreciated

phpnovice
06-06-2005, 03:35 PM
Cheers.