JavaScript code to load image randomly.

Last post 05-12-2008 5:25 AM by jagan.unique. 5 replies.

Sort Posts:

  • JavaScript code to load image randomly.

    05-11-2008, 3:08 AM
    • Member
      11 point Member
    • khoshru
    • Member since 02-04-2008, 12:01 PM
    • Dhaka, Bangladesh
    • Posts 42

     Hi all,

    I want to load image randomly in a page. So what should I have to do. Can I write the Javascript code in PageLoad on aspx.cs page?

    Please write me the code.
      

    Khoshru
    Dhaka, Bangladesh
  • Re: JavaScript code to load image randomly.

    05-11-2008, 3:20 AM
    • Star
      14,584 point Star
    • david wendelken
    • Member since 07-27-2005, 11:47 PM
    • Fayetteville, NC, USA
    • Posts 2,076
    • Moderator

    khoshru:

    I want to load image randomly in a page. So what should I have to do.
      

     

    ASP.Net provides an AdRotator control for just that purpose.  Just drag it on and fill in the properties! 

    khoshru:

    Please write me the code.

     

    Most people are more than happy to help you write the code.   If you have some difficulties getting the AdRotator to work, just post your specific questions and we'll all be glad to help! :)

    If this answered your question, be sure to mark it as the answer. That way, everybody after you will know it's the answer also!
  • Re: JavaScript code to load image randomly.

    05-11-2008, 4:12 AM
    • Member
      11 point Member
    • khoshru
    • Member since 02-04-2008, 12:01 PM
    • Dhaka, Bangladesh
    • Posts 42

    Hi, Thanks for your replay.

    But I want to write Javascript code in aspx.sc file. I don't want to write code on aspx page or don't want to use Adrotator control  then what should I have to do. 

    Khoshru
    Dhaka, Bangladesh
  • Re: JavaScript code to load image randomly.

    05-11-2008, 8:00 AM
    Answer
    • Participant
      1,092 point Participant
    • blodfox777
    • Member since 07-12-2007, 12:30 PM
    • Posts 159

    Hi khoshru

    try the following code, hope it helpsSmile

     

    <html><head>
    <script language="javascript">
    
    today=new Date(); 
    jran=today.getTime(); 
    function rnd() { 
    ia=9301; 
    ic=49297; 
    im=233280; 
    jran = (jran*ia+ic) % im; 
    return jran/(im*1.0); 
    }; 
    
    function rand(number) { 
    return Math.ceil(rnd()*number); 
    }; 
    
    document.write("<center>"); 
    for(i=1;i<=1;i++) { 
    myNum=(rand(3));
    if(myNum == 1) document.write("<img src='http://static.asp.net/asp.net/images/books/book170.jpg'>"); 
    if(myNum == 2) document.write("<img src='http://static.asp.net/asp.net/images/books/book179.jpg'>");  
    if(myNum == 3) document.write("<img src='http://static.asp.net/asp.net/images/books/book171.jpg'>");  
    else { 
    document.write(); 
    }
    
    }; 
    document.write("</center>");
    
    </script> 
    <title>OK</title></head>
    <body>
    
    </body>

     </html>

     

    Regards!

    -- "Mark As Answer" If my reply helped you --
  • Re: JavaScript code to load image randomly.

    05-12-2008, 4:27 AM
    Answer
    • Contributor
      2,778 point Contributor
    • sivakl_2001
    • Member since 01-11-2008, 8:13 AM
    • Kuala Lumpur, Phileo Damansara
    • Posts 802

    HI koshhru try this simple codin

    <script language="javascript">

    var ran=Math.random()*5;

    var ran_number=Math.floor(ran);

    var images = new Array("dot-net-green.gif","load.gif","roller.gif","simple.gif","0003.gif","rotating_arrow.gif")

    document.getElementById("img1").src= "../Img/"+ images[ran_number];

    </script>

  • Re: JavaScript code to load image randomly.

    05-12-2008, 5:25 AM
    Answer
    • Participant
      1,250 point Participant
    • jagan.unique
    • Member since 02-08-2008, 4:42 AM
    • Hyderabad, India
    • Posts 237

    Similar post. check out this link:

    http://forums.asp.net/t/1234164.aspx 

    Click “Mark as Answer” on the post(s) that helped you.
Page 1 of 1 (6 items)