Your HostICan Community  


Go Back   Your HostICan Community > Programming & Design > Javascript / Java Applets

Javascript / Java Applets Are you a JavaScript guy? Do you need help with JavaScript? This is the place to talk about anything related to Java.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 03-25-2009, 01:20 PM
mombo mombo is offline
Junior Member
 
Join Date: Mar 2009
Posts: 2
Default random pictures

I need from a simple code on JavaScript with which can randomly change pictures on my website. My site is small and I don`t want to install any complicated content management system. I want only a little code to work.
Reply With Quote
  #2  
Old 03-25-2009, 02:09 PM
marci marci is offline
Senior Member
 
Join Date: Jan 2009
Location: EU
Posts: 117
Default Re: random pictures

This is the most elementary code for this purpose.
HTML Code:
<html>
<head>
<script type="text/javascript">
var images = new Array();
images[1] = "image1.jpg";
images[2] = "image2.jpg";
images[3] = "image3.jpg";
images[4] = "image4.jpg";
images[5] = "picimage5.jpg";
function randomImage() {
var i = Math.floor(Math.random()*images.length);
document.images['randomImage'].src=images[i];
}
</script>
</head>
<body onload="randomImage()">
<img name="randomImage" alt="">
</body>
</html> 
pic1.jpg, pic2.jpg, pic3.jpg, pic4.jpg, pic5.jpg - Enter the path and name of the pictures. Add as many rows you want.
- Please this line in your web where you want to show the images.
Reply With Quote
  #3  
Old 04-21-2009, 12:01 AM
angelad angelad is offline
Junior Member
 
Join Date: Apr 2009
Posts: 17
Default Re: random pictures

Quote:
Originally Posted by marci View Post
This is the most elementary code for this purpose.
HTML Code:


var images = new Array();
images[1] = "image1.jpg";
images[2] = "image2.jpg";
images[3] = "image3.jpg";
images[4] = "image4.jpg";
images[5] = "picimage5.jpg";
function randomImage() {
var i = Math.floor(Math.random()*images.length);
document.images['randomImage'].src=images[i];
}



pic1.jpg, pic2.jpg, pic3.jpg, pic4.jpg, pic5.jpg - Enter the path and name of the pictures. Add as many rows you want.
- Please this line in your web where you want to show the images.

That's pretty useful, thanks.
Reply With Quote
Reply

Tags
pictures, random

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 On

Forum Jump


All times are GMT -4. The time now is 01:28 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.

Copyright © 2003 - 2008 HostICan. All Rights Reserved.