I have a folder which contains some images:
image1-1.jpg
image1-2.jpg
image2-1.jpg
image2-2.jpg
image2-3.jpg
image2-4.jpg
image3-1.jpg
image3-2.jpg
and a series of links:
link 1
link 2
link 3
I want to use just JavaScript so that when a user clicks on one of these links the corresponding images will be loaded and inserted into my webpage. I have tried with a for loop but it always inserts the amount of images of the highest 'category' of images. For example I click link 1 but it inserts 4 images because image2 goes up to 4.
I've tried this:
var category = <somenumber>
var img = new Image();
for(var i=1;i<375/*the max is 374 images*/;i++){
img.src = "image"+category+"-"+I+".jpg";
if(img.width != 0){
$('<img src="'+img.src+'" width="200">').appendTo('#imgbox');// I use jquery to
}
}
PS: I'm trying not to use php or anything like that