Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Old 10-10-2004, 12:45 PM JavaScript Help!!!
Ark
Ark's Avatar
Webmaster Talker

Posts: 563
Name: Ark
Location: USA
Trades: 0
Hi guys,

I need some help with javascript. How do you change an image on reload... I mean everytime the page reloads a new image should be displayed... Please give me the script to this ASAP... thanks in advance
__________________
Ark

Please login or register to view this content. Registration is FREE
Ark is offline
Reply With Quote
View Public Profile Visit Ark's homepage!
 
 
Register now for full access!
Old 10-10-2004, 02:18 PM
ejumblesale's Avatar
Extreme Talker

Posts: 240
Location: Kent
Trades: 0
<script language="JavaScript" type="text/javascript">
var Image1 = new Image();
Image1 = "pictures/adsamaz.JPG";
var Image2 = new Image();
Image2 = "pictures/adsebay.JPG";
var Image3 = new Image();
Image3 = "pictures/ads.JPG";
var Image4 = new Image();
Image4 = "pictures/tips.jpg";
var url = "advertising.htm";
var Image5 = new Image();
Image5 = "pictures/inthegarden.JPG";
var i = 0;
var z = 0;

function preload()
{

//Use a random calculate here to decide which image to use
var num = rand(5);
if(num==1) document.images[1].src = Image1; // [1] is the image number on page ie if only one image then it would be 0.
else if(num==2) document.images[1].src=Image2;
//continue with all images

}

function rand(num) {
return Math.floor(Math.random() * num+1); /*returns a random number between 1 and the number it is given*/
}

</script>

</head>

<body bgcolor="#FFFFFF" onLoad = "preload();">

All the fundamentals are there hopefully you will be able to get how to do it.
__________________

Please login or register to view this content. Registration is FREE
- The Internet Jumble Sale,

Please login or register to view this content. Registration is FREE
- Personal space containing interesting articles and information on downloadable scripts

Please login or register to view this content. Registration is FREE
- Free link exchange directory and PPC advertising scheme

Please login or register to view this content. Registration is FREE
- The ejumblesale forums
ejumblesale is offline
Reply With Quote
View Public Profile Visit ejumblesale's homepage!
 
Old 10-10-2004, 02:43 PM
Ark
Ark's Avatar
Webmaster Talker

Posts: 563
Name: Ark
Location: USA
Trades: 0
It is not working..
__________________
Ark

Please login or register to view this content. Registration is FREE
Ark is offline
Reply With Quote
View Public Profile Visit Ark's homepage!
 
Old 10-10-2004, 07:16 PM
ejumblesale's Avatar
Extreme Talker

Posts: 240
Location: Kent
Trades: 0
Could you tell me the url of your code? The code I inserted does work because I use it myself on my site?

The main mistakes you could have made are:

document.images[0].src = ... the number in the array has to be the number that the picture is on the page so if one picture then it would be 0 if it is the second picture down it would be one.

The code does work, I have made a page for you so you cna see it working
http://www.ejumblesale.net/preloadImage.htm

Hope that helps.
__________________

Please login or register to view this content. Registration is FREE
- The Internet Jumble Sale,

Please login or register to view this content. Registration is FREE
- Personal space containing interesting articles and information on downloadable scripts

Please login or register to view this content. Registration is FREE
- Free link exchange directory and PPC advertising scheme

Please login or register to view this content. Registration is FREE
- The ejumblesale forums
ejumblesale is offline
Reply With Quote
View Public Profile Visit ejumblesale's homepage!
 
Reply     « Reply to JavaScript Help!!!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23095 seconds with 12 queries