JavaScript - Javascript Random Menu Picture
Hi everyone,
I'd really appreciate some help, I'm trying to make the menu of my website randomly change. I have 6 different image folders in which there are 7 pictures which all read the same things (menu, drawings, photo's etc) but in different writing. I want the website to (when refreshed, or when somebody clicks on one of the menu buttons) randomly pick a folder each time, and use the images of that folder. So the images are all the same name, just the folder needs changing. This is what I have so far (thanks to another forum aswell), which doesn't work. I'm very new to javascript... I can't really 'read' what is says, unlike html and/or css. I 'get' html and css. This really frustrates me. Help?!?! btw: I took everything out that doesn't concern this problem, for easier reading. Code: <html> <head> <title></title> <link type="text/css" rel="stylesheet" href="css/desktop.css" media="screen" /> <script type="text/javascript" src="js/prototype.js"></script> <script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script> <script type="text/javascript" src="js/lightbox.js"></script> <script type="text/javascript"> function randomSort(a,b) { return( parseInt( Math.random()*6 ) %2 ); } var baseURL = 'http://www.SITE.nl/'; var mijnmenu = ['images/pl2/menubalpen','images/pl2/menugeo','images/pl2/menuinkt','images/pl2/menukleur','images/pl2/menupotlood','images/pl2/menusephia']; function randomizeMenu() { var rndMenu = mijnmenu.sort(randomSort); var menuObj= document.getElementById('menu').getElementsByTagName('img'); for (var i=0; i<menuObj.length; i++) { menuObj[i].src = baseURL+'/'+rndMenu[i]+'img'; } } </script> </head> <body onload="randomizeMenu()"> <div id="wrapper"> <div id="menu"> <a href="index.html"><img src="menu1.jpg" /></a> <a href="drawings.html"><img src="menu2.jpg" /></a> <a href="typo.html"><img src="menu3.jpg" /></a> <a href="photo.html"><img src="menu4.jpg" /></a> <a href="movies.html"><img src="menu5.jpg" /></a> <a href="other.html"><img src="menu6.jpg" /></a> <a href="contact.html"><img src="menu7.jpg" /></a> </div> <div id="largecolumn"> TEXT </div> </div> </body> </html> Similar TutorialsWhy can I not change the initial picture from the menu? If I remove the initial image, the menu works as needed. However, when the initial image is used the script will not work. I desperately need the help of a real JS Guru. Frank Sorry. Here it is. how can I write on a picture with javascript? For part of my program I need a function that will switch two images, so when image 1 is clicked on, the function saves image 1, then image 2 is clicked on, and the spot where image 2 is receives the first image, while the place where image 2 was becomes the first image, a simple swapping function. yet, I'm having trouble writing it; this is what I have: <script> click=1 function swap(What input do I need? the img src?){ if (click==1){ var1=imgsrc click=2 } else{ var2=imgsrc //then switch them so: x=var1 var1=var2 var2=x click=1 } } </script> I'm new to coding and recently undertook the position as my school district's webmaster. We use a six day schedule where the days are labeled A-F. I want to be able to display the Today is...A graphic based on the date. I tried some scripts from other forums, but it does not appear to be working. Any suggestions? TY <code> <script language="javascript"> <!-- var picture=''; mytime=new Date(); mymonth=mytime.getMonth()+1; mydate=mytime.getDate(); if (mymonth==9 && mydate==13){picture="<img src=/images/d.gif>"; } if (mymonth==9 && mydate==14){picture="<img src=/images/e.gif width=150 height=150 alt=E>"; } if (mymonth==9 && mydate==15){picture="<img src=/images/f.gif width=150 height=150 alt=F>"; } if (mymonth==9 && mydate==16){picture="<img src=/images/A.gif width=150 height=150 alt=A>"; } if (mymonth==9 && mydate==19){picture="<img src=/images/B.gif width=150 height=150 alt=B>"; } if (mymonth==9 && mydate==20){picture="<img src=/images/c.gif width=150 height=150 alt=C>"; } //--> </script></code> Is there a line of code I can add to my slideshow code to have the slideshow activated by mouseOver and show the main picture on mouseOut, or do I have to redo the code? I've been searching online for a while and can't find anything that works. Any help would be appreciated! Code: <script language="JavaScript1.1"> <!-- /* JavaScript Image slideshow: By JavaScript Kit (www.javascriptkit.com) Over 200+ free JavaScript here! */ var slideimages=new Array() function slideshowimages(){ for (i=0;i<slideshowimages.arguments.length;i++){ slideimages[i]=new Image() slideimages[i].src=slideshowimages.arguments[i] } } //--> </script> <img src="https://lh3.googleusercontent.com/-_ZBn3vpI1aM/TeT4Ty9Dh8I/AAAAAAAABQ8/OWXNUQfXn5U/butterfly.png" name="slide" border=0 width=50 height=47> <script> <!-- //configure the paths of the images, plus corresponding target links slideshowimages("https://lh6.googleusercontent.com/-bPZjekuMNX8/TeT4TyZ2z7I/AAAAAAAABRA/swrVvRqHTpM/butterfly1.png","https://lh6.googleusercontent.com/-fM-kMmy3STQ/TeT4T_aq5hI/AAAAAAAABRE/oq4rGMy8-Qs/butterfly2.png","https://lh3.googleusercontent.com/-jR41bich1pw/TeT4UFyGefI/AAAAAAAABRI/2V8B6bx8P0o/butterfly5.png", "https://lh3.googleusercontent.com/-_ZBn3vpI1aM/TeT4Ty9Dh8I/AAAAAAAABQ8/OWXNUQfXn5U/butterfly.png") //configure the speed of the slideshow, in miliseconds var slideshowspeed=200 var whichlink=0 var whichimage=0 function slideit(){ if (!document.images) return document.images.slide.src=slideimages[whichimage].src whichlink=whichimage if (whichimage<slideimages.length-1) whichimage++ setTimeout("slideit()",slideshowspeed) } slideit() //--> </script> <p align="center"><font face="arial" size="-2">This free script provided by</font><br> <font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript Kit</a></font></p> Hi all, I having a problem. I am having 10 images, and I three places on a webpage where I want to show 3 out of those 10 images randomly. But when for example image 5 is shown on spot 1, it cannot be shown on spot 2 or 3 and the same for spot 2 and 3. Is this possible with Javascript? Greetz, Bob i have a table with a couple random numbers, and i want to click a button that will dynamically regenerate the numbers each time the button is clicked without re-generating the entire table., im using DOM and innerhtml for these random numbers. heres the javascript and html code. so far, it just generates the random numbers when the page loads. i posted this problem a while back, and the answers were great, but they coded the xhtml inside the html file. i'm trying to get the numbers to generate in the table that is formed in the javascript file using innerhtml. i tried to incorporate the solutions without putting the html inside the html file to no avail. var random = Math.floor(Math.random()*40 + 1) //sets variables for random numbers to generate var random2 = Math.floor(Math.random()*40 + 1) var random3 = Math.floor(Math.random()*40 + 1) var random4 = Math.floor(Math.random()*40 + 1) var random5 = Math.floor(Math.random()*40 + 1) var random6 = Math.floor(Math.random()*40 + 1) //create table function makeTable(lotto) document.getElementById("tableSpan").innerHTML = '<table border="1" id="lotto">'; var caption=document.getElementById('lotto').createCaption(); caption.innerHTML="JavaScript Random Numbers"; var x=document.getElementById('lotto').insertRow(0); var cell1=x.insertCell(0); var cell2=x.insertCell(1); var cell3=x.insertCell(2); var cell4=x.insertCell(3); var cell5=x.insertCell(4); var cell6=x.insertCell(5); cell1.innerHTML='<td class = "normal">'+ random +'</td>'; cell2.innerHTML='<td class = "normal">'+ random2 +'</td>'; cell3.innerHTML='<td class = "normal">'+ random3 +'</td>'; cell4.innerHTML='<td class = "normal">'+ random4 +'</td>'; cell5.innerHTML='<td class = "normal">'+ random5 +'</td>'; cell6.innerHTML='<td class = "red">'+ random6 +'</td>'; } heres the HTML file: <body onload="makeTable('lotto');"> <div id="container"> <div id="header"> <h1>Welcome</h1> </div> <div id="content"> <span id="tableSpan"></span> <input type="button" value="Re-generate Numbers" onclick="makeTable('lotto');" /> </div> { ***I need to randomise the order of some questions that are in this format. Any ideas? Thank you!*** <CODE> <!---Question4---> <form name="form4" method="post" action=""> <h3><p>First One</p></h3> <p> <label><input type="radio" name="q4" id="w1" value="1" </label> <label><input type="radio" name="q4" id="w2" value="2" </label> <label><input type="radio" name="q4" id="w3" value="2" </label> </p> </form </CODE> Hello, We are conducting a ceremony in an Auditorium where 336 People are gathered and afterwards we want to choose 20 of them randomly. We want to display the whole act of choosing them via projectors on the auditorium screen with a little animation. Basically the concept of the animation goes like this: http://summercampdubai.com , but we are stuck on the code as none of us knows programming that much: we want the chairs to be GRAY and the one that miss the opportunity (randomly) to turn RED (this much we have done) and the last chair (winner) to REMAIN GRAY (this is where we are stuck)r. PS. can anybody help us with this by tomorrow 10:00 AM GMT? Regards, Sara can you explain someone step by this code?i didn't get it. <script language="Javascript"> <!-- function backcolor(form){ temp = "" for (var i = 0; i < 16; i++) { temp = form.color[i].value if (form.color[i].checked){ document.bgColor = temp } } } function randombackground(){ document.bgColor = getColor() } function getColor(){ currentdate = new Date() backgroundcolor = currentdate.getSeconds() if (backgroundcolor > 44) backgroundcolor = backgroundcolor - 45 else if (backgroundcolor > 29) backgroundcolor = backgroundcolor - 30 else if (backgroundcolor > 15) backgroundcolor = backgroundcolor - 16 if (backgroundcolor == 0 ) return "olive"; else if (backgroundcolor == 1 ) return "teal"; else if (backgroundcolor == 2 ) return "red"; else if (backgroundcolor == 3 ) return "blue"; else if (backgroundcolor == 4 ) return "maroon"; else if (backgroundcolor == 5 ) return "navy"; else if (backgroundcolor == 6 ) return "lime"; else if (backgroundcolor == 7 ) return "fuschia"; else if (backgroundcolor == 8 ) return "green"; else if (backgroundcolor == 9 ) return "purple"; else if (backgroundcolor == 10 ) return "gray"; else if (backgroundcolor == 11 ) return "yellow"; else if (backgroundcolor == 12 ) return "aqua"; else if (backgroundcolor == 13 ) return "black"; else if (backgroundcolor == 14 ) return "white"; else if (backgroundcolor == 15 ) return "silver"; } // --> </script> I have a form that used php to load a random image but now i would like to use javascript instead and am sure I nearly have it. I need to have a random number between 0 -5. Here is my code Code: <script type='text/javascript'> var random = Math.floor( Math.rand() * 6); document.write("<img src='images/'"+random+"'.jpg' alt='random image' /><input name='image' type='hidden' value='"+random+"' />") </script> Hi, I've got a game 99% finished, basically when the game start and the player clicks through to the game panel, there are 30 tiles (80x80px) each, and the object of the game is for the player to press the tile with the letter "X" on, the X can be on any 1 of 5 different coloured tiles at anyone time and of course there can be more than 1 tile having an X on it. The tiles currently are built via .css, and this works 100% perfectly. However now I want to use images, pulled in from my local website instead of tiles built via .css. A demo of what I'm kinda of after is here > Edit fiddle - JSFiddle - if you press "run" the images will keep changing their order. The code I currently have for the game is here.. //CODE// var TheColorArray = ['red', 'yellow', 'green', 'blue', 'orange'], TheScore = 0, TimerLength = 2500, GameTimer, ScoreMap = { 'red': 500, 'yellow': 50, 'green': 30, 'blue': 20, 'orange': 5 }; function DrawRow() { TheColorArray.sort(function () { return .5 - Math.random(); }); var TheHTML = '<div class="row">'; var MagicColumn = Math.floor(Math.random() * 6); for (var i = 0; i < 5; i++) { if (i === MagicColumn) { TheHTML = TheHTML + '<div class="GameTile ' + TheColorArray[i] + '">x</div>'; } else { TheHTML = TheHTML + '<div class="GameTile ' + TheColorArray[i] + '">' + String.fromCharCode(97 + Math.floor(Math.random() * 26)) + '</div>'; } } TheHTML = TheHTML + '</div>'; return TheHTML; } You'll also see that "TheHTML = TheHTML + '<div class="GameTile ' + TheColorArray[i] + '">x</div>';" and "TheHTML = TheHTML + '<div class="GameTile ' + TheColorArray[i] + '">' + String.fromCharCode(97 + Math.floor(Math.random() * 26)) + '</div>';" both state that if X is pressed the game basically carries on. I need this to use a chosen image from my server, i.e. URL/apple.png .... i have also managed to get to this point (with apples) but its just not working.. Edit fiddle - JSFiddle Any help would be great.. Many thanks in advance!!! Hi All. I am new to all this and I am posting a problem up here that I think is quite rare or has not been looked into for a long time now. I am basically looking to create a background for my website and when you refresh the page the image changes to another picture for the background. I have asked one of my good friends to have a look at it and he gave me some code to work with and so I have changed bits here and there and it worked in firefox and safari but will not work in IE. When I asked him he had no clue what to do. So here I am now! I am hoping it is simple but I also know it wont be to an extent! Any help would be much appreciated here. I have attached the code here for you and also the html file. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> </head> <style type="text/css"> <!-- #myFlash { position:absolute; width:100%; height:100%; margin:0; padding:0; left:0; right:0; z-index:20; } --> </style> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Experts Connect</title> <meta name="keywords" content="Experts connect Preston, Experts connect Lancashire, Medical reports, Preston medical and legal agency, Lancashire medical and legal agency, specialist providers of independent medical evidence, diagnostic and rehabilitation services to the personal injury market, Medico Legal, personal injury claims, refferers." /> <meta name="description" content="Experts Connect are an established legal and medical agency providing reports for persobal injury claims. We work to get the best possible examination we can to ensure your claim goes through with no fuss. We are based nationally and work all over the United Kingdom." /> <meta name="robots" content="INDEX,FOLLOW" /> <meta name="revisit-after" content="10 days" /> <link rel="stylesheet" type="text/css" href="/common/basic.css" /> <script type="text/javascript" src="crossfade.js"></script> <script type="text/javascript" src="swfobject.js"></script> <script type="text/javascript"> swfobject.registerObject("myFlashContent", "9.0.0", "expressInstall.swf"); </script> <style type="text/css"> body { width:auto; height:auto; background-color:#CCCCCC;} #bgimage { filter:alpha(opacity=40); -moz-opacity:0.40; -khtml-opacity:0.40; opacity:0.40; width:100%; height:100%; position:absolute; margin:0; padding:0; left:0; right:0; } </style> <title>Untitled Document</title> <SCRIPT LANGUAGE="JavaScript"> <SCRIPT/> <!-- Begin // Set up the image files to be used. var theImages = new Array() // do not change this // To add more image files, continue with the // pattern below, adding to the array. theImages[0] = 'back4.jpg' theImages[1] = 'back2.jpg' theImages[2] = 'back5.jpg' theImages[3] = 'back6.jpg' theImages[4] = 'back8.jpg' // do not edit anything below this line var j = 0 var p = theImages.length; var preBuffer = new Array() for (i = 0; i < p; i++){ preBuffer[i] = new Image() preBuffer[i].src = theImages[i] } var whichImage = Math.round(Math.random()*(p-1)); function showImage(){ document.write('<img id="bgimage" src="'+theImages[whichImage]+'">'); // End --> </script> </head> <div id="myFlash"> <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="100%" height="100%" id="myFlashContent" name="expertsconnect" align="middle"> <param name="movie" value="experts-connectwebsite.swf" /> <param name="quality" value="high" /> <param name="scale" value="exactfit" /> <param name="wmode" value="transparent" /> <param name="allowfullscreen" value="true" /> <param name="allowscriptaccess" value="always" /> <!--[if !IE]>--> <object type="application/x-shockwave-flash" data="experts-connectwebsite.swf" width="100%" height="100%" align="middle"> <param name="quality" value="high" /> <param name="scale" value="exactfit" /> <param name="wmode" value="transparent" /> <param name="allowfullscreen" value="true" /> <param name="allowscriptaccess" value="always" /> <!--<![endif]--> <a href="http://www.adobe.com/go/getflashplayer"> <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /> </a> <!--[if !IE]>--> </object> <!--<![endif]--> </object> </div> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin showImage(); // End --> </script> <!-- Script Size: 1.49 KB --> </body> </html> There is also a flash file embedded into this document! Any help would be great with this. Thank you, Mark Hello, I need help again :3 Heres what I need: I need some javascript to random a script. Simply like this: The script randoms a number Based on the number it runs some lines of PHP script. Random 1-10 If 1 Then run this PHP script *PHP script* *PHP script* *PHP script* *PHP script* If 2 Then run this PHP script *Different PHP script* *Different PHP script* *Different PHP script* *Different PHP script* If 3 Then run this PHP Script *some more different PHP Script* *some more different PHP Script* *some more different PHP Script* *some more different PHP Script* If 4 etc etc etc Each bit of PHP Will be similar, but be different in some ways. There may be more compressed ways of doing this. But if it at all possible, I would like it in the way I wrote it above. For instance I dont want: Random 1-3 If 1 Run function 1 If 2 Run function 2 If 3 Run function 3 Function 3 *PHP Script* *PHP Script* *PHP Script* Function 1 *PHP Script* *PHP Script* *PHP Script* Function 2 *PHP Script* *PHP Script* *PHP Script* I will thank the best answer! This website is awesome and has answered so many of my questions! Thanks in advance! Hi all.. I've been trying to get random numbers in JS. It works when I assign fixed values, but when I want those values to come from a form, I get all the problems.. any comments on my script? Thanks. M [CODE] <script type="text/javascript"> function random() { var x=document.getElementById("text1").value;// num ingresado por el usuario var y=document.getElementById("text2").value; //var x=1; //var y=6; num=Math.floor(x + Math.random() * y); var r=document.getElementById("demo") r.innerHTML=num; } </script> [CODE] I am trying to make it so that when the page loads, it will random play a song from a list of songs. Also, when the first song finishes, another random song should play. I have this code: Code: <script type="text/javascript"> var numberOfSongs = 5 var sound = new Array(numberOfSongs+1) sound[0]= "music/Rock/1.mp3" sound[1]= "music/Rock/2.mp3" sound[2]= "music/Rock/3.mp3" sound[3]= "music/Rock/4.mp3" sound[4]= "music/Rock/5.mp3" sound[5]= "music/Rock/6.mp3" function randomNumber() { var randomLooper = -1 while (randomLooper < 0 || randomLooper > numberOfSongs || isNaN(randomLooper)){ randomLooper = parseInt(Math.random()*(numberOfSongs+1)) } return randomLooper } var soundFile = sound[randomNumber ()] document.writeln ('<BGSOUND SRC="' + soundFile + '" loop=5>'); document.writeln ('<EMBED SRC= "' + soundFile + '" loop=5 PLAYCOUNT=3 hidden=true autostart=true><P>'); </script> How would it be possible to play another random song after the song finishes? Hi, I have a Javascript which I'm using to display one of four Flash SWF files randomly. These need to be actually displayed twice, so I'm basically calling the script twice. This works great aside from one thing- occasionally the same movie appears in both scripts, for example the first instance picks movie 3 of 4 and th second instance does the same. What I need is to somehow make sure that if the first instance of the script picks movie x then the second script will pick any movie EXCEPT movie x. This is the script as it stands: Code: <script language="JavaScript"> // Generate a Random Number var randomnumber = Math.round(Math.random()*3); // Select a swf and execute the corresponding function if (randomnumber == 1) {movie1();} else if (randomnumber == 2) {movie2();} else if (randomnumber == 3) {movie3();} else {movie4();} //Functions to write out the correct flash movie resource. function movie1(){ document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0\" width=\"120\" height=\"285\"><param name=movie value=\"assets/images/ads/hotels/1.swf\"><param name=quality value=high><embed src=\"assets/images/ads/hotels/1.swf\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"120\" height=\"285\"></embed></object>") } function movie2(){ document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0\" width=\"120\" height=\"285\"><param name=movie value=\"assets/images/ads/hotels/2.swf\"><param name=quality value=high><embed src=\"assets/images/ads/hotels/2.swf\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"120\" height=\"285\"></embed></object>") } function movie3(){ document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0\" width=\"120\" height=\"285\"><param name=movie value=\"assets/images/ads/hotels/3.swf\"><param name=quality value=high><embed src=\"assets/images/ads/hotels/3.swf\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"120\" height=\"285\"></embed></object>") } function movie4(){ document.write("<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0\" width=\"120\" height=\"285\"><param name=movie value=\"assets/images/ads/hotels/4.swf\"><param name=quality value=high><embed src=\"assets/images/ads/hotels/4.swf\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"120\" height=\"285\"></embed></object>") } </script> What I am trying to do is make a little box that when you hover over it, it will move to a random position. What I am having trouble with is the JavaScript. I have made the code for everything, EXCEPT to move it to a random position. Here is my code so far: Code: <style type='text/css'> #circle1 { background:#007fff; height:20px; margin:0px; position:absolute; width:20px; left:5px; top:5px; -webkit-transition:left 2s linear, top 2s linear; } #circle1:hover { left:25px; top:25px; -webkit-transition:left 0s linear, top 0s linear; } </style> <div id='circle1'></div> I would like the left: and top: in the #circle1:hover to be a random number, to make it go to a random position. I have no clue how to do that though... Ok got a random image display and have tried to make it so once the image is displayed it is taken out of the array so it can not be viewed again untill there are no more elements in the array, problem is, it doesn't work. Have been told about shuffle, but not very keen on that. Can someone shed some light. 4 images, with accompaning links to be displayed 4 times, all unique. Code: Code: <script language="JavaScript"> function random_imglink(){ var myimages=new Array() myimages[0]="http://ads.factorymedia.com/www/images/fbm_oct10_300x80.gif" myimages[1]="http://ads.factorymedia.com/www/images/rbbyd_web_banner_300x80_animated.gif" myimages[2]="http://ads.factorymedia.com/www/images/2010_vex_300x80.jpg" myimages[3]="http://ads.factorymedia.com/www/images/image_3.gif" var imagelinks=new Array() imagelinks[0]="http://www.4downdistribution.com/" imagelinks[1]="http://www.redbull.co.uk/cs/Satellite/en_UK/Event/Red-Bull-Backyard-Digger-021242831811513" imagelinks[2]="http://verdebmx.com/" imagelinks[3]="http://www.zealbmx.com/" var count; for(count=0; count<myimages.length; count++) { if (myimages.length>0) { var ry=Math.floor(Math.random()*myimages.length) document.write('<div class="feed2"><a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" height=64px width=240px border=0></a></div>') if (ry>0 && ry<myimages.length-1) { myimages=concat(myimages. (0,ry-1),myimages.slice(ry+1,myimages.length-1)); imagelinks=concat(imagelinks.slice(0,ry-1),imagelinks.slice(ry+1,imagelinks.length-1)); } if (ry==0) { myimages=myimages.slice(1,myimages.length-1); imagelinks=imagelinks.slice(1,imagelinks.length-1); } if (ry==myimages.length-1) { myimages=myimages.slice(0,ry-1); imagelinks=imagelinks.slice(0,ry-1); } } } } </script> <script language="JavaScript"> random_imglink(); </script> an alternative way that also didn't work Code: function random_imglink(){ var myimages=new Array(); myimages[0]="http://ads.factorymedia.com/www/images/fbm_oct10_300x80.gif"; myimages[1]="http://ads.factorymedia.com/www/images/rbbyd_web_banner_300x80_animated.gif"; myimages[2]="http://ads.factorymedia.com/www/images/2010_vex_300x80.jpg"; myimages[3]="http://ads.factorymedia.com/www/images/image_3.gif"; var imagelinks=new Array(); imagelinks[0]="http://www.4downdistribution.com/"; imagelinks[1]="http://www.redbull.co.uk/cs/Satellite/en_UK/Event/Red-Bull-Backyard-Digger-021242831811513"; imagelinks[2]="http://verdebmx.com/"; imagelinks[3]="http://www.zealbmx.com/"; var indexes = [0, 1, 2, 3]; index.sort(function (){ reutrn 0.5 - Math.random(); }); for(var count=0; count < index.length; count++) { var ry = indexes[count]; document.write('<div class="feed2"><a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" height=64px width=240px border=0></a></div>'); } } So I found this script and i give all props to the author but can anyone help me to add text to the random images. Also i need a button that will generate the random images/text not when you refresh the page but when your press the button and to not display any image/text till the button is pressed? Thanks in advance. [CODE] <script language="Javascript"> var currentdate = 0 var core = 0 function StringArray (n) { this.length = n; for (var i =1; i <= n; i++) { this[i] = ' ' } } image = new StringArray(10) image[0] = 'images' image[1] = 'images' image[2] = 'images' image[3] = 'images' image[4] = 'images' image[5] = 'images' image[6] = 'images' image[7] = 'images' image[8] = 'images' image[9] = 'images' var ran = 60/image.length function ranimage() { currentdate = new Date() core = currentdate.getSeconds() core = Math.floor(core/ran) return(image[core]) } document.write("<img src='" +ranimage()+ "'>") </script> <form> <p><input type="button" name="B1" value="Switch It Up" onclick="ranimage()"></p> </form> [CODE] |