Re: Random image script
[code:s36vkfg1]
<script type="text/javascript">
/**
Script Title: Random Image with Link [configurable via array]
Script Author: Raymond Angana as first seen on devppl.com/forum [username = rangana]
Date Created: 3/4/09
This notice must stay intact for legal use
*/
var ray = {
imgs:
[
['deck/card1.jpg','http://www.google.com'],
['deck/card2.jpg','http://www.yahoo.com'],
['deck/card3.jpg','http://www.card3.com'],
['deck/card4.jpg','http://www.msn.com'],
['deck/card5.jpg','http://www.card5.com'],
['deck/card6.jpg','http://www.cnn.com']
],
getID:function(el) {
return document.getElementById(el);
},
randomPic:function (el) {
var aTag = this.getID(el);
var rand = Math.floor(Math.random()*this.imgs.length);
var imgSrc = aTag.innerHTML.split('src="')[1].split('"')[0];
aTag.href = this.imgs[rand][1];
aTag.getElementsByTagName('img')[0].src = this.imgs[rand][0];
}
}
</script>
<a id="picturelink" href="#"><img src="deck/0.jpg" name="picture" /></a>
<input type="button" value="pick a card" onclick="ray.randomPic('picturelink')">
[/code:s36vkfg1]