Old 15th June 2002, 23:14   #1
tjb2004
Major Dude
 
tjb2004's Avatar
 
Join Date: Jun 2000
Location: Rocky River, Ohio.
Posts: 1,881
Send a message via AIM to tjb2004
Qucik HTML/Java/ect help.

I need a Java code or any simple code that will show a random picture from a selection of them. Any help is appreciated.
tjb2004 is offline   Reply With Quote
Old 15th June 2002, 23:35   #2
baafie
feminazi
(Major Dude)
 
baafie's Avatar
 
Join Date: Apr 2001
Posts: 1,767
Let's say that you stack a bunch of your pictures in an array and randomly use an image fromt that array:
code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function randompic()
{
var pic_array = new Array("one.jpg", "two.jpg", "three.jpg", "four.jpg", "five.jpg",
"six.jpg", "seven.jpg", "eight.jpg", "nine.jpg", "ten.jpg");
var randomnumber = Math.round(Math.random()*10);
randpicture.src = pic_array[randomnumber];
}
</script>
</head>
<body onload="randompic()">
<img src="" alt="random picture" id="randpicture">
</body>
</html>


Note: I have not tested this script.
baafie is offline   Reply With Quote
Old 16th June 2002, 01:43   #3
tjb2004
Major Dude
 
tjb2004's Avatar
 
Join Date: Jun 2000
Location: Rocky River, Ohio.
Posts: 1,881
Send a message via AIM to tjb2004
Where would I keep the array?
tjb2004 is offline   Reply With Quote
Old 16th June 2002, 02:25   #4
deadrabbit
Major Dude
 
deadrabbit's Avatar
 
Join Date: Nov 2001
Location: VT, US
Posts: 612
here's my code from a couple years ago, i'd highly advise against using though, it doesn't work sometimes, it seems to be random (ironically), i can't figure out why . .. if anyone can spot a problem, i'd appreciate it . ..

<script language="javascript">
<!--
//The Random Image Generator, created by DR, Senior Chief Random Image Generation Specialist,
// and also son of God.
//When you create an image that you wish to change randomly upon loading, the image tag must
// include name="it", and should be followed by the script that runs the test function.
function test()
{
var pic=new Image();
var now=new Date();
var seed=now.getTime()%0xffffffff;
//Set n to the total number of images you have
var n=10;
seed=(seed%(n*10))+11;
pic.src=name;
//Add a if statement like this 3 for each of the images you have
if (seed==16)
pic.src="r1.gif";
if (seed==26)
pic.src="r2.gif";
if (seed==36)
pic.src="r3.gif";
if (seed==46)
pic.src="r4.gif";
if (seed==56)
pic.src="r5.gif";
if (seed==66)
pic.src="r6.gif";
if (seed==76)
pic.src="r7.gif";
if (seed==86)
pic.src="r8.gif";
if (seed==96)
pic.src="r9.gif";
if (seed==106)
pic.src="r10.gif";
// document.write(seed);
document.it.src=pic.src;
}

//-->
</script>

baafie's script is much tidier, i think i'll try it . ..
deadrabbit is offline   Reply With Quote
Old 16th June 2002, 02:28   #5
deadrabbit
Major Dude
 
deadrabbit's Avatar
 
Join Date: Nov 2001
Location: VT, US
Posts: 612
and by the way, the array in baafie's script is part of the code, you don't need to "keep it" anywhere . . . i think, it's been a long time since i've used javascript
deadrabbit is offline   Reply With Quote
Old 16th June 2002, 02:36   #6
GoldenSphynx
Forum King
 
GoldenSphynx's Avatar
 
Join Date: Mar 2002
Posts: 2,738
Quote:
Originally posted by baafie
Let's say that you stack a bunch of your pictures in an array and randomly use an image fromt that array:
code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function randompic()
{
var pic_array = new Array("one.jpg", "two.jpg", "three.jpg", "four.jpg", "five.jpg",
"six.jpg", "seven.jpg", "eight.jpg", "nine.jpg", "ten.jpg");
var randomnumber = Math.round(Math.random()*10);
randpicture.src = pic_array[randomnumber];
}
</script>
</head>
<body onload="randompic()">
<img src="" alt="random picture" id="randpicture">
</body>
</html>


Note: I have not tested this script.
Could you teach me Javascript baafie??? Please!??
GoldenSphynx is offline   Reply With Quote
Old 16th June 2002, 02:53   #7
deadrabbit
Major Dude
 
deadrabbit's Avatar
 
Join Date: Nov 2001
Location: VT, US
Posts: 612
i tried it out, works great . . . you might want to add height and width to your img tags, all the pics came out at 10 x 10 pixels in opera, i didn't try any other browsers

hurrah baafie!
deadrabbit is offline   Reply With Quote
Old 16th June 2002, 09:03   #8
baafie
feminazi
(Major Dude)
 
baafie's Avatar
 
Join Date: Apr 2001
Posts: 1,767
Quote:
Originally posted by GoldenSphinx86

Could you teach me Javascript baafie??? Please!??
For a minute there I thought you were Xerxes, but since you're not, I won't teach you :P You'll just have to .. RTFM
Quote:
i tried it out, works great . . . you might want to add height and width to your img tags, all the pics came out at 10 x 10 pixels in opera, i didn't try any other browsers
Try it in IE, I think it'll work fine there; if it doesn't I'll modify the code some.

[edit]Try this piece of code; this way the script will work with any amount of images:
code:

function randompic()
{
var pic_array = new Array("one.jpg", "two.jpg", "three.jpg", "four.jpg", "five.jpg",
"six.jpg", "seven.jpg", "eight.jpg", "nine.jpg", "ten.jpg");
var randomnumber = Math.floor(Math.random() * pic_array.length);
randpicture.src = pic_array[randomnumber];
}


[/edit]

Last edited by baafie; 16th June 2002 at 11:39.
baafie is offline   Reply With Quote
Old 16th June 2002, 09:14   #9
rm'
Banned
 
rm''s Avatar
 
Join Date: Jul 2000
Posts: 11,361
That, folks, is what years of dedicated service does for you, as opposed to incessant newbie bashing.

Moral of the story: be a good kid.
rm' is offline   Reply With Quote
Old 16th June 2002, 19:50   #10
tjb2004
Major Dude
 
tjb2004's Avatar
 
Join Date: Jun 2000
Location: Rocky River, Ohio.
Posts: 1,881
Send a message via AIM to tjb2004
Quote:
Originally posted by deadrabbit
and by the way, the array in baafie's script is part of the code, you don't need to "keep it" anywhere . . . i think, it's been a long time since i've used javascript
I ment where do I place the pictures and how does it know where to find them?
tjb2004 is offline   Reply With Quote
Old 16th June 2002, 19:53   #11
GoldenSphynx
Forum King
 
GoldenSphynx's Avatar
 
Join Date: Mar 2002
Posts: 2,738
Make sure that the code is in the same directory as the pictures.
GoldenSphynx is offline   Reply With Quote
Old 16th June 2002, 19:56   #12
tjb2004
Major Dude
 
tjb2004's Avatar
 
Join Date: Jun 2000
Location: Rocky River, Ohio.
Posts: 1,881
Send a message via AIM to tjb2004
What happens if I have a different directory for images?
tjb2004 is offline   Reply With Quote
Old 16th June 2002, 19:57   #13
GoldenSphynx
Forum King
 
GoldenSphynx's Avatar
 
Join Date: Mar 2002
Posts: 2,738
Then you have to update the code to fit into the image directory.
GoldenSphynx is offline   Reply With Quote
Old 16th June 2002, 19:59   #14
baafie
feminazi
(Major Dude)
 
baafie's Avatar
 
Join Date: Apr 2001
Posts: 1,767
You just modify the array. For instance, you could use this array:

var pic_array = new Array("images/mydog.jpg", "images/mycat.gif");
baafie is offline   Reply With Quote
Old 16th June 2002, 20:12   #15
tjb2004
Major Dude
 
tjb2004's Avatar
 
Join Date: Jun 2000
Location: Rocky River, Ohio.
Posts: 1,881
Send a message via AIM to tjb2004
Ok, thanks. I'll try it out now.
tjb2004 is offline   Reply With Quote
Old 16th June 2002, 20:28   #16
tjb2004
Major Dude
 
tjb2004's Avatar
 
Join Date: Jun 2000
Location: Rocky River, Ohio.
Posts: 1,881
Send a message via AIM to tjb2004
Kick Ass!

It worked! Check it out here! It's the one above sweet pics. Thanks for all your help!
tjb2004 is offline   Reply With Quote
Old 16th June 2002, 20:34   #17
GoldenSphynx
Forum King
 
GoldenSphynx's Avatar
 
Join Date: Mar 2002
Posts: 2,738
All I see is a little red 'x'. Hey baf, do you recommend any books/sites to help me learn JS??
GoldenSphynx is offline   Reply With Quote
Old 16th June 2002, 20:50   #18
Bilbo Baggins
Wind Chime of the Apocalypse
 
Bilbo Baggins's Avatar
 
Join Date: May 2000
Location: The Forest
Posts: 17,229
www.htmlgoodies.com
Bilbo Baggins is offline   Reply With Quote
Old 16th June 2002, 20:52   #19
GoldenSphynx
Forum King
 
GoldenSphynx's Avatar
 
Join Date: Mar 2002
Posts: 2,738
Ohh, I've been there before, for html help...any others?? Thx Bilbo
GoldenSphynx is offline   Reply With Quote
Old 16th June 2002, 21:06   #20
baafie
feminazi
(Major Dude)
 
baafie's Avatar
 
Join Date: Apr 2001
Posts: 1,767
What's with you and useless one-liners GoldenSphinx86?
I recommend Danny Goodman's Javascript Bible.
baafie is offline   Reply With Quote
Old 16th June 2002, 21:08   #21
GoldenSphynx
Forum King
 
GoldenSphynx's Avatar
 
Join Date: Mar 2002
Posts: 2,738
Fine,
then
I
won't
post
one-
liners.
Thank
you
Baafie
and
Bilbo

GoldenSphynx is offline   Reply With Quote
Old 16th June 2002, 22:37   #22
tjb2004
Major Dude
 
tjb2004's Avatar
 
Join Date: Jun 2000
Location: Rocky River, Ohio.
Posts: 1,881
Send a message via AIM to tjb2004
Quote:
Originally posted by GoldenSphinx86
All I see is a little red 'x'.
It loads after the page loads for some reason. Didn't work too well in IE though.
tjb2004 is offline   Reply With Quote
Old 16th June 2002, 23:13   #23
baafie
feminazi
(Major Dude)
 
baafie's Avatar
 
Join Date: Apr 2001
Posts: 1,767
This should work better:
code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
function randompic()
{
var pic_array = new Array("one.jpg", "two.jpg", "three.jpg");
var randomnumber = Math.floor(Math.random() * pic_array.length);
randpicture.src = pic_array[randomnumber];
}
</script>
</head>
<body>
<img src="nothere.jpg" alt="random picture" id="randpicture" onError="randompic()">
</body>
</html>

baafie is offline   Reply With Quote
Old 17th June 2002, 03:01   #24
tjb2004
Major Dude
 
tjb2004's Avatar
 
Join Date: Jun 2000
Location: Rocky River, Ohio.
Posts: 1,881
Send a message via AIM to tjb2004
Thanks. I'll try that tomorrow.
tjb2004 is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Community Center > General Discussions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump