description change

They have: 56 posts

Joined: Feb 2000

I wrote a javascript that has a next and back button and 12 images it goes through. once the script get to image 12 it unlinks the next button. i want to have a text description for each of the 12 images. if i am on image 1 and i click on the "next" button, how can i change the text description below it for that image?

The trouble with doing something right the first time is that nobody appreciates how difficult it was.

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi,

The answer depends upon your code. I'm going to assume you have your pics in an array and that it is called myPics. The principle behind the answer is:
1) place your text within an array
var picDescriptions = new Array();
picDescriptions[0] = "This is description for pic1";
picDescriptions[1] = "This is description for pic2";
etc.
2) declare your pics & text array as global (outside of any function, just after the <script language='javascript'> tag) Do the same for:
var currentPic = 0;
3) the html for the buttons:

4) the function:
function showPic(isNext)
{
if (isNext) currentPic++;
else currentPic--;

document.imagename.src = myPic[currentPic];
document.formname.textbox.value = picDescriptions[currentPic];
}

Didn't test this (because I wrote it here), but it or some facsimile should work

Vinny

Where the world once stood
the blades of grass cut me still

They have: 56 posts

Joined: Feb 2000

is there any way to do it without layers or text boxes? I was thinking you could pissibly do it with document.write but i can't get it to change once they click the next buttin. here is my code so you can see it:

this goes in the HEAD
<script language="Javascript">
=no_images) {document.nxt.src=next_off.src;}
else {document.nxt.src=next_on.src; document.prv.src=prev_on.src;}
if (newnumber>no_images) {return false}
else {image_num=newnumber;
selectionNext = "samplegallery/"+image_num+".jpg";
document.family.src = selectionNext;}
}
//-->
</script>

this goes in the BODY:

<script language="Javascript">
');}
else {document.write('');}
//-->
</script>

Close Gallery


<script language="Javascript">
');}
else {document.write('');}
//-->
</script>

<script language="javascript">
');
//-->
</script>

The trouble with doing something right the first time is that nobody appreciates how difficult it was.

Vincent Puglia's picture

They have: 634 posts

Joined: Dec 1999

Hi Rage,

You can't use document.write() once the page has loaded. If you do, you will get a new page. The easiest solution is to use a textbox for the description. If you don't want to use them or dHTML, make the description an image then you can swap them back and forth. But (and there is always a but) load time will increase.
If you don't know dHTML, see the "dHTML: an Introduction" script at my site. It teaches as well as supplies you with code you can use.

Vinny

Where the world once stood
the blades of grass cut me still

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.