/    Sign up×
Community /Pin to ProfileBookmark

making images in slideshow array clickable

Hi,

I am a newbie to javascript and have some code for a slideshow that works fine, the only thing is that the images in the ary array are not clickable. Here is the code :

[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” xml:lang=”en” lang=”en”>

<head>
<title></title>
</head>

<body>
<script type=”text/javascript”>
<!–
var ary=[
‘batman_arkham_asylum.jpg’,
‘borderlands.jpg’,
‘brink.jpg’,
‘mini_ninjas.jpg’,
‘prince_of_persia.jpg’,
‘spiderman_shattered_dimensions.jpg’
];

function Slide(id,ary,nu){
document.getElementById(id).src=ary[nu];
Slide[id]={nu:nu}; // create a function Slide[id] object with a property of nu recording the current image number
}

function nextImage(id,ary,ud){
var nu=(Slide[id]&&Slide[id].nu?Slide[id].nu:0)+ud; // if the function Slide[id] object exists use that or use 0 and add ud
Slide(id,ary,Math.min(Math.max(nu,0),ary.length-1));
}

//–>
</script>

<img src=”previous.png” name=”previous” height=”46″ width=”46″ onmouseup=”nextImage(‘slideshow’,ary,-1);” id=”previous”/>

<img src=”next.png” name=”next” height=”46″ width=”46″ onmouseup=”nextImage(‘slideshow’,ary,1)” id=”next”/>

<img src=”batman_arkham_asylum.jpg” name=”slide” id=”slideshow”/>

</body>

</html>
[/CODE]

how would I make the jpegs clickable, I have tried using hrefs but it didn’t work, any help would be greatly appreciated, thanks.

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@JMRKERApr 22.2015 — By "clickable", what do you want them to do?

What is supposed to happen when they are clicked?
Copy linkTweet thisAlerts:
@saco721authorApr 22.2015 — when the images are clicked, it should navigate to a new page. Thanks
Copy linkTweet thisAlerts:
@JMRKERApr 22.2015 — Where?
Copy linkTweet thisAlerts:
@saco721authorApr 22.2015 — Just to a html page on my website, for example clicking on batman_arkham_asylum.jpg should take you to batman.html. As the script is only in the development stage, the full url would be http://localhost/batman.html, borderlands.jpg to http://localhost/borderland.html etc. Thanks!
Copy linkTweet thisAlerts:
@JMRKERApr 22.2015 — Significantly modified ...

<i>
</i>
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"&gt;
&lt;head&gt;
&lt;title&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;style type="text/css"&gt;
.directionImage { font-size:2em; border:1px solid red; background-color:red; cursor:pointer; }
#prev { float:left; }
#next { float:right; }
br { clear:both; }
&lt;/style&gt;

&lt;body&gt;

&lt;div style="width:300px;text-align:center"&gt;
&lt;span id="prev" class="directionImage"&gt;&amp;lt;--&lt;/span&gt;
&lt;span id="next" class="directionImage"&gt;--&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;a href="#" id="linkSlide"&gt;
&lt;img src="" alt="" id="slideshow" width="200px"&gt;
&lt;/a&gt;
&lt;/div&gt;

&lt;script type="text/javascript"&gt;
(function () {
var baseURL = 'http://www.nova.edu/hpd/otm/pics/4fun/'; // change to your directory
var ary = [
'11.jpg|http://www.google.com',
'12.jpg|http://www.bing.com',
'13.jpg|http://www.yahoo.com',
'14.jpg|http://www.webdeveloper.com/forum/forumdisplay.php?3-JavaScript',
'15.jpg|http://www.codingforums.com/javascript-programming/' // use your filenames|links below

/* images not provided
'batman_arkham_asylum.jpg', 'borderlands.jpg',
'brink.jpg', 'mini_ninjas.jpg',
'prince_of_persia.jpg', 'spiderman_shattered_dimensions.jpg'
*/
];

var slideNo = 0;
function getLink(flag) {
var info = ary[slideNo];
var tarr = info.split('|'); // alert(tarr[0]+'n'+tarr[1]);
if (flag) { return tarr[1]; } else { return tarr[0]; }
}
function Slide(direction) {
slideNo = slideNo + (direction*1);
if (slideNo &lt; 0) { slideNo = ary.length-1; }
if (slideNo &gt; ary.length-1) { slideNo = 0; }
document.getElementById('slideshow').src = baseURL+getLink(false);
document.getElementById('slideshow').alt = baseURL+getLink(false);
document.getElementById('linkSlide').href = getLink(true);
}

document.getElementById('slideshow').src = baseURL+getLink(false);
document.getElementById('slideshow').alt = baseURL+getLink(false);
document.getElementById('linkSlide').href = getLink(true);

document.getElementById('prev').onclick = function() { Slide(-1); }
document.getElementById('next').onclick = function() { Slide(1); }
}())

&lt;/script&gt;
&lt;/body&gt;

&lt;/html&gt;



Note comments within code concerning your images and links.

Good Luck!

?
Copy linkTweet thisAlerts:
@saco721authorApr 23.2015 — Hey JMRKER,

Thank you so much for your time!,

best wishes,

Saco.
Copy linkTweet thisAlerts:
@JMRKERApr 24.2015 — Your're most welcome.

Happy to help.

Good luck!

?
×

Success!

Help @saco721 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.23,
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,
)...