I am a complete novice so apologies in advance. I want to have a gallery on my website that looks something like the attachment. There is an image in the middle cell of the table and the current image number in the top cell as part of the navigation buttons (prev 1/9 next).

I have got as far as making the buttons change the image when clicked on but I cannot work out how to make the number change as well (2/9, 3/9 etc) when each new image comes up (please see the code below).

Is there an easy way of doing this?

Many thanks for any assistance offered!

<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>


  <script language="JavaScript"><!--
which_image = 0;
var x;

ImageNames = new Object();
ImageNames.length = NUMBER_OF_IMAGES - 1;

for (counter = 0; counter < NUMBER_OF_IMAGES; counter++){
    file_number = counter + 1;
	x = counter + 1;
    filename = ("images_1/" + file_number + ".jpg");
    ImageNames[counter] = filename;


function changeImage(direction) {
    which_image += direction;
    if (which_image < 0)
        which_image = NUMBER_OF_IMAGES - 1;
    if (which_image == NUMBER_OF_IMAGES)
        which_image = 0;
    if (document.images)
        document.myimage.src = ImageNames[which_image];

 <script type="text/javascript">

<table width="600" height="661" border="0" cellpadding="5">
    <td><input type="button" value="<<" onclick='changeImage(-1);' /> 
    <input type=button value=">>" onclick='changeImage(1)' /></td>
   <td><img src="images_1/1.jpg" name=myimage width=400 height=500 /></td>
    <td height="112">&nbsp;</td>

Recommended Answers

All 2 Replies

Thank you, but I wanted to know if there is a simple way of altering this code to get there. The other galleries use different methods of achieving this effect and also, they are much more fancy in style; I want a very simple look as displayed in the attachment.

I appreciate that you could simplify the style but I am not good enough at Javascript to know which bits to amend.

Any thoughts on whether it is possible to get the image numbers showing with this code?(please see initial post)


Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.