[Java Script]Random Pics

luish

OSNN Senior Addict
#1
Hey !
I need a script to show random pic and i need a bit of help.
I found a script, and I changed it a bit but i need to to random the names of the pics too. i will explain.
I got pics in a directory let's say Images, that are numbered,like1205.jpg, 1206.jpg, etc... and I want the script to random me anumberfrom 2067-2089 (the name of the pics I want to random). and showthemrandomaly... but I got a problem doin it.
This is the script i got... how can i upgrade it for my needs ?

Code:
<script language="JavaScript">
<!--

function random_images(){
  var myimages=new Array()
 
  myimages[1]="1.jpg"
  myimages[2]="2.jpg"

  var ry=Math.floor(Math.random()*myimages.length)

  if (ry==0)
	 ry=1
	 document.write('<img src="'+myimages[ry]+'" border=0>')
}

//-->
</script>


<SCRIPT language="JavaScript">
<!--
random_images()
//-->
</SCRIPT>
Anyone ?
 

j79zlr

Glaanies script monkey
Political User
#2
This is all you would need, put this in your <head> section

Code:
<script type="text/javascript">
<!--
function random_images() {
  var num_of_pics;
  var starting_number;
  num_of_pics=22;
  starting_number=2067;
  rand=Math.random()*num_of_pics + starting_number;
  document.write("<img src=\"images/" + Math.round(rand) + ".jpg\" />");
}
//-->
</script>
The where you want the image:

<script type="text/javascript">
<!--
random_images()
//-->
</script>
 

Members online

No members online now.

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there https://tinyurl.com/ycpxl
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,971
Messages
673,300
Members
89,016
Latest member
Poseeut