Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Thread Tools Search this Thread
Old 25-02-2009
Join Date: Dec 2008
Posts: 43
Upload image randomly with JavaScript Page

i want to know to how to upload image randomly with javascript page.Any recommendations and suggestions are appreciated.
Reply With Quote
Old 25-02-2009
Join Date: Apr 2008
Posts: 2,001
Re: Upload image randomly with JavaScript Page

<script language="JavaScript"> 
  <! -- 
  img = new Array () 
  ran = Math.floor (4 * Math.random ()); 
  img [0] = 'immagine1.jpg "width =" "height =" "border =""'; 
  img [1] = 'immagine2.jpg "width =" "height =" "border =""'; 
  img [2] = 'immagine3.jpg "width =" "height =" "border =""'; 
  img [3] = 'immagine4.jpg "width =" "height =" "border =""'; 
  document.write ( "<img src=\""+img[ran]+"\">"); 
  / / -> 
  </ script>
This is the code to upload image randomly with javascript.
Reply With Quote
Old 25-02-2009
Join Date: Oct 2005
Posts: 2,389
Re: Upload image randomly with JavaScript Page

matrix array instantiated with a new type of variable. Although JavaScript does not have any type of data matrix, it is possible create a structure array defining an object array. By doing this, you can create properties for the object contains the data you need.img = new Array ()check a name to the matrix with the same operator = This operator assigns the variable the value of the left than the right. Every time you call the variable img will be referred to the matrix and properties of the data.
Reply With Quote
Old 25-02-2009
Join Date: May 2008
Posts: 2,008
Re: Upload image randomly with JavaScript Page

Now create the variable for the random function, to extract a given random in this case an image and access the individual properties of the matrix ran = Math.floor (4 * Math.random ()); The Math object provides constants and mathematical functions beyond those provided by standard operators for addition, subtraction, multiplication, etc. ...

in which each character represents the function to perform.The Math object is considered static, ie does not require an instance of to use the properties and methods of the object. There is no new statement to create a copy of Math. The method Math.floor (number) shows the nearest integer towards zero ES: Math.floor (32.5) becomes 32 you make a test with the examples below :
<script> document.write (Math.floor (32.5)) </ script>
If the decimal part of N and ? '0.5 ? N is rounded up 0 Same for negative numbers -24.8 becomes -25
<script> document.write (Math.floor (-24.8)) </ script>
After the method Math.floor between parentheses put the number of array elements this example the 4 and multiply them by using the method Math.random () the method Math.random () will extract a random from among those included in the elements of the matrix Construction matrix elements img [0] = 'immagine1.jpg "width =" "height =" "border =""'; Method: identifier [number] where the identifier is the variable that calls img matrix array, img [0] img [1] img [2] img [3] Nb. the first number assigned to the identification, inserted between the brackets must be zero [0]

if we start from a [1] img [1] img [2] img [3] img [4] this picture will never be displayed img [0] = 'immagine1.jpg "width =" "height =" "border =""'; if you want comfort or convenience first identifier assigned to the No. [1] nodificate variable ran like this: ran = Math.floor (4 * Math.random () +1); after the identifier just insert the images to be displayed Just img [0] = 'immagine1.jpg', but is recommended to enter the dimensions of the images to avoid (although slight) a slowdown in the loading of the browser having to perform this function This is the part that deals with the display of object document.write image document.write ( "<img src=\""+img[ran]+"\">"); we put the tag <img src =, the variable for the matrix img Array and between the brackets variable ran [ran] to the identifiers and the function random.
Reply With Quote

  TechArena Community > Software > Software Development
Tags: , ,

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads for: "Upload image randomly with JavaScript Page"
Thread Thread Starter Forum Replies Last Post
How can I upload videos on sky drive page mANICKAVASAN Technology & Internet 3 30-10-2010 11:26 AM
Bridge CS4 and Web Gallery upload blank page issue Abhisar G Windows Software 5 12-07-2010 02:31 PM
Refresh after upload an image in jsp Adrina_g Software Development 4 11-02-2010 09:43 PM
How to upload my profile image on Facebook Daniel23 Technology & Internet 3 20-11-2009 12:24 AM
Html replace browse image upload Brunoz Software Development 3 04-08-2009 03:24 PM

All times are GMT +5.5. The time now is 04:01 AM.