Ok I need help editing this script I am currently using. After using Google and looking all over the internet I failed to find an answer to my problem so I decided to come here. First off this is what I want to do. When the random picture pops up I want text to go with it. So I want these two div tags to go with each picture so I can add with the text hit counter and rating like the random game thing on armorgames.com. <script language="JavaScript" type="text/javascript"> function random_imglink(){ var myimages=new Array() myimages[1]="random_games_img/1.gif" myimages[2]="random_games_img/2.gif" myimages[3]="random_games_img/3.gif" myimages[4]="random_games_img/4.gif" myimages[5]="random_games_img/5.gif" myimages[6]="random_games_img/6.gif" var imagelinks=new Array() imagelinks[1]="http://www.google.com" imagelinks[2]="http://www.google.com" imagelinks[3]="http://www.google.com" imagelinks[4]="http://www.google.com" imagelinks[5]="http://www.google.com" imagelinks[6]="http://www.google.com" var ry=Math.floor(Math.random()*myimages.length) if (ry==0) ry=1 document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>') } random_imglink() </script> Code (markup): So their is my code. Eventually where the link says google it will go to my pages. Anyway I want the div boxes to be these two. <div class="disciption">Game Name <div class="indiscription">Loved 19 times</div> </div> Code (markup): Which connect to my main style sheet. If this doesn't make sense I want an script that chooses a random Image from a folder with the image having a link to a page. Then next to the box the title to the right and under it spot to place stuff like hit counter and rating. Thanks In advanced!
I know on this forum everyone looks down on double posting but has been a couple days still haven't found answer can someone please help, I just want to have certain divs pop up with each image thanks.
you are probably not getting a reply as you only have 4 posts outside of this thread and you just expect others to do your reading and coding for you... no wonder google searching comes empty. any reputation you give will also be without merit. anyway... first off - your data needs to be unified. you seem to have properties to each game - these are: image, url, loved and title. chances are your data is coming through mysql so my advice is, read it all into one big PHP array and then use php5's function json_encode(); to export into your javascript. the js itself needs to change like so: <div id="random"></div> <script type="text/javascript"> // this data ought to be dynamic from PHP -> JSON or JSONP from external sources etc, but it needs to come to the following (as many images as you want it to have): var data = [ { image: "random_games_img/1.gif", url: "http://www.url1.com", title: "Random Game 1 is crap", loved: "19" }, { image: "random_games_img/2.gif", url: "http://www.url2.com", title: "Random Game 2 is good", loved: "1332" }, { image: "random_games_img/3.gif", url: "http://www.url3.com", title: "Random Game 3 is average", loved: "1332" } ]; // end array. var showRandomImage = function() { var r = Math.floor(Math.random() * data.length), outputHTML = "<div class='disciption'><a href='"; outputHTML += data[r]['url']; outputHTML += "'><img src='"; outputHTML += data[r]['image']; outputHTML += "' border='0' /></a><br />"; outputHTML += data[r]['title']; outputHTML += "<div class='indiscription'>Loved "; outputHTML += data[r]['loved']; outputHTML += " times</div></div>"; // output will go into whatever element is called 'random' - using document.write is a VERY BAD practice for speed. document.getElementById("random").innerHTML = outputHTML; }; window.onload = function() { // if you already have onload / domready, then integrate there.... showRandomImage(); }; </script> PHP: i hope this makes sense - if not, read up on: window.onload document.getElementById JSON and ARRAYS in javascript avoiding document.write