|
|
#1 (permalink) |
|
Bow before Surpass!
Super #1
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
|
Random Java Help
Yes, I need help with Java (or Javascript). I need to display random HTML coding, loaded with page (meaning no extra link, etc, automatically random and changes with reloads of the page). I've checked the net, no luck as of yet, but I need this to display a random image on each reload of the page. But this has the be in an HTML way, as each image will have it's own link.
What is this for? Well, as some or many may know, E3 2006 had just finished last Friday (the 12th) and I will have articles about each of the anticipated/popular games and events. The feature portion of the design will have a image with general info. To make things cooler, that feature image can be at "random" allowing multible images to appear for each event covered article. To make this more than looks (and better basically), having each random image as a link to different sections will assist those interested in the featured game/event. Thank you ![]()
__________________
Wii Hotspot - Upcoming project! -http://www.wiihotspot.com
Make a cPanel Login Form | Why is my Account Suspended? |
|
|
|
|
|
#2 (permalink) |
|
Surpass Fan
Excelling Contributor
Joined in Nov 2005
Lives in Colorado
Hosted on DEDI
937 posts
Gave thanks: 2
Thanked 95 times
|
Do you want the same image during the user's entire stay, or, would you like the images to change, say every 30 seconds while the user is on the page?
If you want a random image to remain, use a javascript or php script to pick an image to place in the <img> tag on load (or reload). If you want a changing image every so many seconds, you do not have to reload the page each time. You can make a container for the image (<div>) and have a javascript replace the contents of the container only.
__________________
Where would you be if you were at the highest court in the land (US)? |
|
|
|
|
|
#3 (permalink) |
|
Bow before Surpass!
Super #1
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
|
Um, I know. I'm not new to codin gin general, I am just not a javascript expert. I've already checked search engines, and all they have is a random image, but no spot to make each image have their own link. And, it is a random image that is not dynamic, and changes on reload as stated in the first post.
Thanks for trying, but I'm past that stage. I'm looking for the code, not how to go about a search ![]()
__________________
Wii Hotspot - Upcoming project! -http://www.wiihotspot.com
Make a cPanel Login Form | Why is my Account Suspended? |
|
|
|
|
|
#4 (permalink) |
|
after g, before i
Resident.
Joined in Jul 2004
Lives in N,BC,CA
8,092 posts
Gave thanks: 48
Thanked 131 times
|
Ok... Here's the jist of what you'd want to do.
In your HTML, you'd have your link and image: Code:
... <a href="url.lnk" id="imageLink"><img src="image.type" alt="blah" id="imagePath" /></a> ... Next, you can do this JavaScript where ever, just make sure you do it after the DOM has loaded (eg: window.onload). So you'd have function, and an array of image paths and links. To make it easier on myself, I'll do two arrays just because I'm not positive if 2-dimensional arrays work like they do in PHP. Code:
var imagePaths = new Array();
imagePaths[0] = 'images/0.jpg';
imagePaths[1] = 'images/1.jpg';
imagePaths[2] = 'images/2.jpg';
var imageLinks = new Array();
imageLinks[0] = 'http://site1.url/';
imageLinks[1] = 'http://site2.url/';
imageLinks[2] = 'http://site3.url/';
function rndImage() {
var randomNum = (Math.round(Math.random()*2));
document.getElementById('imagePath').src = imagePaths[randomNum];
document.getElementById('imageLink').src = imageLinks[randomNum];
}
window.onload = rndImage;
|
|
|
|
|
|
#5 (permalink) |
|
Surpass Fan
Super #1
Joined in Aug 2004
Hosted on SH58
1,688 posts
Gave thanks: 6
Thanked 7 times
|
I believe that the following line
Code:
document.getElementById('imageLink').src = imageLinks[randomNum];
Code:
document.getElementById('imageLink').href = imageLinks[randomNum];
__________________
- Evan Charlton | [site] | Server - SH58 |
|
|
|
|
|
#7 (permalink) |
|
Bow before Surpass!
Super #1
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
|
Thank you!!!
__________________
Wii Hotspot - Upcoming project! -http://www.wiihotspot.com
Make a cPanel Login Form | Why is my Account Suspended? |
|
|
|
|
|
#9 (permalink) |
|
rocks your socks.
Resident.
Joined in Mar 2004
Lives in fear of Obama.
Hosted on Pass 7
13,170 posts
Gave thanks: 8
Thanked 35 times
|
I was going to take an online class in this a while back, but when I went to pay for it I discovered they didn't do online payments. So, I wait until this time around to find a different school...they too do not do online payments. They do however, teach ecommerce. You'd think they'd utilize it.
|
|
|
|