/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Basic Slide Show

Iv got this script which changes the image using simple next and previous buttos from a predefined list, however it doesnt change the name or “title” of the image. seems like some code is missing? Can anyone help?

[CODE]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Simple slideshow</title>
<script type=”text/javascript”>
/* <![CDATA[ */
var pots = [
{
“title”:”Aubergines”,
“path”:”images/front.jpg” },
{
“title”:”Pineapple and Tofu”,
“path”:”images/side.jpg” },
{
“title”:”Rabbit”,
“path”:”images/large.jpg”},
{
“title”:”Blueberry Pies”,
“path”:”images/blueberries_pie.jpg”}
];
var pos = 0;
function switchImage() {
if (pos>=pots.length)
pos=0;
else if(pos<0)
pos=pots.length-1;
document.images[0].src=pots[pos][“path”];
}
/* ]]> */
</script>
</head>
<body onload=”javascript:document.getElementById(‘title’).innerHTML=pots[pos][‘title’];”>
<h1 style=”text-align:center”>Very basic slide-show</h1>
<div style=”text-align:center”>
<p><img src=”images/front.jpg” alt=”Recipes” /></p>
<p id=”title”>&nbsp;</p>
<p style=”text-align:center”><a href=”javascript:pos–;switchImage();”>previous</a> <a href=”javascript:pos++;switchImage();”>next</a>
</p>
</div>
</body>
</html>[/CODE]

thanks.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Rufe0Apr 13.2011 — function switchImage() {

if (pos>=pots.length)

pos=0;

else if(pos<0)

pos=pots.length-1;

document.images[0].src=pots[pos]["path"];

document.getElementById("title").innerHTML = pots[pos]["title"];

}
Copy linkTweet thisAlerts:
@mike-web-devauthorApr 13.2011 — function switchImage() {

if (pos>=pots.length)

pos=0;

else if(pos<0)

pos=pots.length-1;

document.images[0].src=pots[pos]["path"];

document.getElementById("title").innerHTML = pots[pos]["title"];

}[/QUOTE]


perfect! thank you very much!! ?

Knew it was a simple fix just didnt no how to amend the html inside the id="title" rather than the id itself, innerHTML seems to do the trick! Thanks!
×

Success!

Help @mike-web-dev spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.15,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...