/    Sign up×
Community /Pin to ProfileBookmark

Change text with image using JS

I have the following script working fine but what I need to do is change the text that appears below the big photo when the respective thumbnail is moused over, i.e., when the mouse is over pic1thumbnail, text related to pic1Big.jpg is displayed at the bottom and when the mouse is over pic2thumbnail, text related to pic2Big.jpg is displayed at the bottom. Any ideas how to achieve this?

<html>
<head>
<script type=”text/javascript” language=”javascript”>
<!–
function update(url,index,isSuper) {
document[‘PhotoBig’].src=url;
}
//–>
</script>
</head>
<body>

<div style=”float:left;”>
<ul style=”list-style:none; margin:0; padding:0;”>
<li style=”float:left;”><a onMouseOver=”update(‘pic1Big.jpg’, 0, false); return false;”><img src=”pic1thumbnail.jpg” alt=””></a>
<li style=”float:left;”><a onMouseOver=”update(‘pic2Big.jpg’, 1, true); return false;”>
<img src=”pic2humbnail.jpg” alt=””></a>
</ul>
</div>

<ul style=”list-style:none; margin:0; padding:0;”>
<li><img src=”pic1Big.jpg” alt=”” name=”PhotoBig”>
<div>Text under pic1Big</div>
</ul>
</body>
</html>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@astupidnameJun 04.2009 — You could do something like this (change image paths back, I used mine while putting together):

[code=html]<html>
<head>
<script type="text/javascript" language="javascript">

var SWAPPER = {
pics : ['images/1big.gif', 'images/2big.gif'], //add in as many image paths as wanted
text : ['Picture One', 'Picture Two'], //ditto for the text
preload : function () {
for (var i = 0, preloaded = []; i < this.pics.length; i++) {
preloaded[i] = new Image();
preloaded[i].src = this.pics[i];
}
},
swap : function (imgId, index, txtElemId) {
document.getElementById(imgId).src = this.pics[index];
if (txtElemId && this.text[index]) { //changing text elements innerHTML is optional
document.getElementById(txtElemId).innerHTML = this.text[index];
}
}
};

SWAPPER.preload(); //preloading optional, comment this call out if no preloading desired

</script>
</head>
<body>

<div style="float:left;">
<ul style="list-style:none; margin:0; padding:0;">
<li style="float:left;"><a onmouseover="SWAPPER.swap('swapPic', 0, 'textDiv'); return false;">
<img src="images/1th.gif" alt="1th.gif" title="1th.gif" width="100" height="100"></a>
<li style="float:left;"><a onmouseover="SWAPPER.swap('swapPic', 1, 'textDiv'); return false;">
<img src="images/2th.gif" alt="2th.gif" title="2th.gif" width="100" height="100"></a>
</ul>
</div>
<div style="float:left; clear:left;">
<ul style="list-style:none; margin:0; padding:0;">
<li><img src="images/1big.gif" alt="1big.gif" title="1big.gif" id="swapPic" width="700" height="700">
<div id="textDiv">Text under pic1Big</div>
</ul>
</div>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@al-zinesauthorJun 04.2009 — Thanks astupidname,

Your idea worked just right. I stared at that script I was using and fiddled with it and knew I had to change image and text but could not get anything to work.

Yours is straightforward and filled the bill...plus, I learned a little about how to use the clear property. Floats have bedeviled me for some time and clearing them helps line things up correctly.
×

Success!

Help @al-zines 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...