473,387 Members | 1,561 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Adding a text caption to this slideshow script

21
Hi guys

I've been using this, my favorite slideshow script for its simplicity. Now I'd like to add a text caption to each image that rotates in-kind, but I'm having trouble working out the dynamics.
Here's the current script:

<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
<!--

myPix = new Array(
"images/picture01.jpg",
"images/picture02.jpg",
"images/picture03.jpg",
"images/picture04.jpg")
thisPic = 0
imgCt = myPix.length - 1

function chgSlide(direction) {
if (document.images) {
thisPic = thisPic + direction
if (thisPic > imgCt) {
thisPic = 0
}
if (thisPic < 0) {
thisPic = imgCt
}
document.myPicture.src=myPix[thisPic]
}
}

// -->
</SCRIPT>

<P><IMG SRC="images/picture01.jpg" NAME="myPicture" WIDTH="300" HEIGHT="200"></P>
<A HREF="javascript:chgSlide(-1)"><< Back</A> <A HREF="javascript:chgSlide(1)">Forward >></A>

I was thinking that I could add this second array, but am stuck on how to integrate the resulting variable into the body:

myCap = new Array(
"Text Caption 01",
"Text Caption 02",
"Text Caption 03",
"Text Caption 04")
thisCap = 0
imgCt = myCap.length - 1

function chgSlide(direction) {
if (document.images) {
thisCap = thisCap + direction
if (thisCap > imgCt) {
thisCap = 0
}
if (thisCap < 0) {
thisCap = imgCt
}
document.myCaption.src=myCap[thisCap]
}
}

Any ideas?
Apr 21 '07 #1
4 3036
Wolfman
21
I found a simple way to use a textarea tag, but it looks junky.

<TEXTAREA NAME=myCaption></TEXTAREA>

I'd like for the text to appear as if it was simple HTML text.
Apr 21 '07 #2
Wolfman
21
I tried combining the variables to no avail, but I think I'm getting closer. This variant tells me, however, that 'myCaption' is null, even though I follow the other array's scripting precisely. What am I doing wrong?

<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
<!--

myPix = new Array(
"images/01.jpg",
"images/02.jpg",
"images/03.jpg")
thisPic = 0
imgCt = myPix.length - 1

myTxt = new Array(
"Caption 1",
"Caption 2",
"Caption 3")
thisTxt = 0
txtCt = myTxt.length - 1

function chgSlide(direction) {
if (document.images) {
thisPic = thisPic + direction
thisTxt = thisTxt + direction
if (thisPic > imgCt) {
thisPic = 0
thisTxt = 0
}
if (thisPic < 0) {
thisPic = imgCt
thisTxt = txtCt
}
document.myPicture.src=myPix[thisPic]
document.myCaption.src=myTxt[thisTxt]
}
}

// -->
</SCRIPT>


<P><IMG SRC="images/01.jpg" NAME="myPicture" WIDTH="50" HEIGHT="40" ALT="Slideshow"></P>
<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
document.write(myCaption)
</SCRIPT><BR>
<A HREF="javascript:chgSlide(-1)">Back</A> <A HREF="javascript:chgSlide(1)">Forward</A>
May 19 '07 #3
Logician
210 100+
document.myCaption.src=myTxt[thisTxt]
You don't have an element called document.myCaption so you cant give it a src property, and even if you could it wouldn't be any use.

Create a <span> element with whatever CSS styling you want, give it an ID attribute, say 'myCaption', include the function below and use it thus:

caption('myCaption', myTxt[thisTxt]);

Expand|Select|Wrap|Line Numbers
  1. function caption(elemId, txt)
  2. {
  3.  var elem;
  4.  
  5.  if(document.getElementById && (elem=document.getElementById(elemId)))
  6.   if(elem.firstChild)
  7.    elem.firstChild.data=txt;
  8.   else
  9.    elem.appendChild(document.createTextNode(txt)); 
  10. }
@ADMIN - Why are we now getting those poxy line numbers that nobody wants?

Alternatively, try a different slideshow
May 20 '07 #4
Wolfman
21
Thanks. I'm motivated to use this one because it's very basic - no transition effects, no page refreshing, no fancy text boxes. Just a picture and some text that can be formatted using traditional tags. Will give your corrections a whirl - and thanks.
May 20 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Steven Choo | last post by:
Hi all, I have used a script which allows visitors of my personal website to click on a small image to see an enlarged version in a pop-up. It would be great if i could add some text within the...
6
by: Amir Hardon | last post by:
I'm new to DOM and can't figure out this thing: I'm trying to add a row to a table with a form field in one of it's cells, but if I'm appending the field to a form it gets out of the table. Can...
4
by: ziggy.696040 | last post by:
My web page has thumbnail pictures, and when the user clicks on a thumbnail, I change the image source of a full-size image elsewhere on the page. I'd also like to change the caption of the...
0
by: Chenghui Li | last post by:
We have a problem with the Windows XP theme: We have a IDE which allows other developers to develop visual programs for their customers. Our IDE allow them to set font for window captions easyly...
11
by: David Graham | last post by:
Hi New to javascript. I'm trying to understand how a script at a website I come across works. http://www.BRPPISAFETY.COM Nearly got it but I have changed the variable called 'crossFadeDuration'...
2
by: Casey Miller | last post by:
I have a site, http://www.onemorewebsite.com, that has a menu on the left side and a picture on the right side with a middle div for content in the middle. When I mouse over the menu, the picture...
8
by: GabrielESandoval | last post by:
i currently use the code below to create a slideshow of images. i edited it so that its not as long. i currently have over 20 images i want to change it so that the images dont appear in the...
6
by: mrtaka79 | last post by:
Okay, first of all, I'm a complete noob, so go easy on me. I have this code that works perfectly for me. The only thing I want to add is to randomize the pictures/links that show up. Can anyone...
1
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.