/    Sign up×
Community /Pin to ProfileBookmark

Random image and text need help….

Hello all,

I’m trying to create a page that load up a random image and text when you enter the website. I’ve found a javascript that does this already but it only does it for the random images. I need some help so that it would randomly load both the images and the plain text (right underneath the image). Would somehelp give me a hand on this? Here is the javascript code below for just the random images.

<script language=”javascript”>
<!–
// Script: Random Image
// Version: 1.0
// Last Updated: June 12th 1998
// Author: Scott Brady
// Org: HotSource HTML Help
// Email: [email][email protected][/email]
// Website: [url]http://www.sbrady.com/hotsource/[/url]

var b1dis = “<a href=””;
var bdis = “”><img src=””;
var edis = “width=”100″ height=”100″ alt=”test images” border=”0″></a>”;
var rnumb = “”;
var img = “”;

rnumb += Math.floor(Math.random()*3);
img = rnumb;
if (img == “0”) {
document.write(b1dis+ “http://www.yahoo.com” +bdis+ “images/pageone.gif”” +edis);
}
if (img == “1”) {
document.write(b1dis+ “http://www.cnn.com” +bdis+ “images/pagetwo.gif”” +edis);
}
if (img == “2”) {
document.write(b1dis+ “http://www.msn.com” +bdis+ “images/pagethree.gif”” +edis);
}
// –>
</script>

Thanks in advance for your help.
–comaiwat

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceMar 02.2006 — That script also places a hyperlink around the image. If you need that I can add it.

New script without hyperlink:
<i>
</i>var myArray = new Array(
new Array("...url_1...", "...text_1..."),
new Array("...url_2...", "...text_2..."),
new Array("...url_3...", "...text_3...")
); // no comma after last element above
var str = "", url = 0, txt = 1;
var idx = Math.round(Math.random()*(myArray.length - 1));
str += '&lt;img src="' + myArray[idx][url] + '"';
str += ' alt="' + myArray[idx][txt] + '"';
str += ' title="' + myArray[idx][txt] + '"';
str += '&gt;';
str += '&lt;div style="text-align:center;"&gt;&lt;p&gt;' + myArray[idx][txt];
str += '&lt;/p&gt;&lt;/div&gt;';
document.writeln(str);
Copy linkTweet thisAlerts:
@comaiwatauthorMar 02.2006 — Thanks you the script. I will put it to use.
×

Success!

Help @comaiwat 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.18,
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,
)...