Saturday, 31 August 2013

Adding hyperlinks to index array in javascript

Adding hyperlinks to index array in javascript

How do I add a link in the description of an index array in javascript? My
code is below, thanks. I tried using push method, but I think I had a
conflict with the showpic function. I really don't know, so I would
appreciate any help.
<script type="text/javascript">
mypic = new Array();
mypic[0]=["images/Lg_image1.jpg","Large image 1 description."] //I want to
add an HTML link to a website at the end of this array
mypic[1]=["images/Lg_image2.jpg", "Large image 2 description."] //I want
to add an HTML link to a website at the end of this array
function showpic2(n){
document.getElementById("mainpic2").src=mypic[n][0]
document.getElementById("mycaption2").innerHTML=mypic[n][1]
count=n
}
count = 0;
function next() {
count++
if (count == mypic2.length) {
count = 0
}
document.getElementById("mainpic2").src=mypic2[count][0]
document.getElementById("mycaption2").innerHTML=mypic2[count][1]
}
function prev() {
count--
if (count<0) {
count = mypic2.length-1
}
document.getElementById("mainpic2").src=mypic2[count][0]
document.getElementById("mycaption2").innerHTML=mypic2[count][1]
}
</script>
</head>
<body>
<div id="container">
<div class="menu1">
<ul>
Link 1
<ul>
<li><a href="#">Link 2</a>
</li>
</ul>
</div>
<div id="large">
<img src="images/Lg_image1.jpg" class="mainpic2" id="mainpic2">
</div>
<div id="thumbs2">
<a href="javascript:showpic2(0)"><img src="images/sm_image1.jpg"
alt="image1"/></a>
<a href="javascript:showpic2(1)"><img src="images/sm_image2.jpg"
alt="image2"/></a>
</div>
<div id="mycaption2">Large image default description.
</div>
<div id="logohome">
<img src="images/#.png" alt="" />
</div>
<div id="homebox">
<img src="images/homebox1.png" alt="" />
</div>
</div>
</body>
</html>

No comments:

Post a Comment