icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.
Old May 14th, 2006, 7:01 AM   #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
__________________
GamingHybrid is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old May 14th, 2006, 11:34 AM   #2 (permalink)
Surpass Fan
Excelling Contributor
 
cowboy's Avatar
 
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)?
cowboy is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old May 14th, 2006, 11:05 PM   #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
__________________
GamingHybrid is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old May 14th, 2006, 11:35 PM   #4 (permalink)
H
after g, before i
Resident.
 
H's Avatar
 
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>
...
These would have default values, just incase JavaScript doesn't load.

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;
This should work, though I haven't tested it.
H is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old May 15th, 2006, 12:16 AM   #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];
should be
Code:
document.getElementById('imageLink').href = imageLinks[randomNum];
__________________
- Evan Charlton | [site] | Server - SH58
Kickersny.com is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old May 15th, 2006, 12:21 AM   #6 (permalink)
H
after g, before i
Resident.
 
H's Avatar
 
Joined in Jul 2004
Lives in N,BC,CA
8,092 posts
Gave thanks: 48
Thanked 131 times
You're right. I was lazy and just copied the first one and didn't replace it.
H is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old May 15th, 2006, 2:02 AM   #7 (permalink)
Bow before Surpass!
Super #1
 
Joined in Sep 2004
1,547 posts
Gave thanks: 91
Thanked 49 times
Thank you!!!
__________________
GamingHybrid is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old May 15th, 2006, 2:31 AM   #8 (permalink)
H
after g, before i
Resident.
 
H's Avatar
 
Joined in Jul 2004
Lives in N,BC,CA
8,092 posts
Gave thanks: 48
Thanked 131 times
Not a problem.
H is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old May 15th, 2006, 5:51 AM   #9 (permalink)
rocks your socks.
Resident.
 
David's Avatar
 
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.
__________________
Quote:
Originally Posted by removed View Post
Internet Explorer rules.
David is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On