Results 1 to 4 of 4

Thread: Upload image randomly with JavaScript Page

  1. #1
    Join Date
    Dec 2008
    Posts
    43

    Upload image randomly with JavaScript Page

    hi,
    i want to know to how to upload image randomly with javascript page.Any recommendations and suggestions are appreciated.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Upload image randomly with JavaScript Page

    Code:
    <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.

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    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.

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    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.

Similar Threads

  1. How can I upload videos on sky drive page
    By mANICKAVASAN in forum Technology & Internet
    Replies: 3
    Last Post: 30-10-2010, 11:26 AM
  2. Bridge CS4 and Web Gallery upload blank page issue
    By Abhisar G in forum Windows Software
    Replies: 5
    Last Post: 12-07-2010, 02:31 PM
  3. Refresh after upload an image in jsp
    By Adrina_g in forum Software Development
    Replies: 4
    Last Post: 11-02-2010, 09:43 PM
  4. How to upload my profile image on Facebook
    By Daniel23 in forum Technology & Internet
    Replies: 3
    Last Post: 20-11-2009, 12:24 AM
  5. Html replace browse image upload
    By Brunoz in forum Software Development
    Replies: 3
    Last Post: 04-08-2009, 03:24 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,631,578.50809 seconds with 17 queries