www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Rate Thread Display Modes
      #1  
    Old 02-09-2010, 11:17 AM
    Trfsorz Trfsorz is offline
    Registered User
     
    Join Date: Feb 2010
    Posts: 2
    resolved [RESOLVED] Trouble with image code!

    Hello,

    I've got a small issue with a image code of mine. It's a random image code. But here comes the part I'm having a problem with, I've customized it to allow me to have two images at the same time. However, they are both linked together. The reason for this is because the images are big so cutting them in two pieces would make the loading quicker. However... It's not working as it should, Here's a link to the style, so you can see the problem (Refresh a couple of times): http://rarewarecentral.com/forums/index.php?styleid=108

    I have checked several times, all the images do exist on my server, all the links are valid ... So It's probably something wrong with my code. Since I'm not any good at javascript at all I'm seeking help.

    This is the code:
    Code:
    <SCRIPT LANGUAGE="JavaScript">
     
    <!-- Begin Random Logo In Header Script
     
    var theImages = new Array() // do not change this
     
    <!-- Edit the url images to match yours
    <!-- Edit the url images to match yours
    theImages[0] = 'http://rarewarecentral.com/forums/images/btc/logo1-1.png'
    theImages[1] = 'http://rarewarecentral.com/forums/images/btc/logo2-1.png'
    theImages[2] = 'http://rarewarecentral.com/forums/images/btc/logo3-1.png'
    theImages[3] = 'http://rarewarecentral.com/forums/images/btc/logo4-1.png'
    theImages[4] = 'http://rarewarecentral.com/forums/images/btc/logo5-1.png'
    theImages[5] = 'http://rarewarecentral.com/forums/images/btc/logo6-1.png'
    theImages[6] = 'http://rarewarecentral.com/forums/images/btc/logo7-1.png'
    theImages[7] = 'http://rarewarecentral.com/forums/images/btc/logo8-1.png'
    theImages[8] = 'http://rarewarecentral.com/forums/images/btc/logo9-1.png'
    theImages[9] = 'http://rarewarecentral.com/forums/images/btc/logo10-1.png'
    theImages[10] = 'http://rarewarecentral.com/forums/images/btc/logo11-1.png'
    theImages[11] = 'http://rarewarecentral.com/forums/images/btc/logo12-1.png'
    theImages[12] = 'http://rarewarecentral.com/forums/images/btc/logo13-1.png'
    theImages[13] = 'http://rarewarecentral.com/forums/images/btc/logo14-1.png'
    theImages[14] = 'http://rarewarecentral.com/forums/images/btc/logo15-1.png'
    theImages[15] = 'http://rarewarecentral.com/forums/images/btc/logo16-1.png'
    theImages[16] = 'http://rarewarecentral.com/forums/images/btc/logo1-2.png'
    theImages[17] = 'http://rarewarecentral.com/forums/images/btc/logo2-2.png'
    theImages[18] = 'http://rarewarecentral.com/forums/images/btc/logo3-2.png'
    theImages[19] = 'http://rarewarecentral.com/forums/images/btc/logo4-2.png'
    theImages[20] = 'http://rarewarecentral.com/forums/images/btc/logo5-2.png'
    theImages[21] = 'http://rarewarecentral.com/forums/images/btc/logo6-2.png'
    theImages[22] = 'http://rarewarecentral.com/forums/images/btc/logo7-2.png'
    theImages[23] = 'http://rarewarecentral.com/forums/images/btc/logo8-2.png'
    theImages[24] = 'http://rarewarecentral.com/forums/images/btc/logo9-2.png'
    theImages[25] = 'http://rarewarecentral.com/forums/images/btc/logo10-2.png'
    theImages[26] = 'http://rarewarecentral.com/forums/images/btc/logo11-2.png'
    theImages[27] = 'http://rarewarecentral.com/forums/images/btc/logo12-2.png'
    theImages[28] = 'http://rarewarecentral.com/forums/images/btc/logo13-2.png'
    theImages[29] = 'http://rarewarecentral.com/forums/images/btc/logo14-2.png'
    theImages[30] = 'http://rarewarecentral.com/forums/images/btc/logo15-2.png'
    theImages[31] = 'http://rarewarecentral.com/forums/images/btc/logo16-2.png'
     
    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-5));
    function showImage(){
    document.write('<img src="'+theImages[whichImage]+'"/></a><img src="'+theImages[whichImage+16]+'"/></a></div>');
    }
     
    // End -->
    </script>
    
    <center>
    <SCRIPT LANGUAGE="JavaScript">
    showImage();
    </script>
    </center>
    I believe the problem should be within:
    Quote:
    function showImage(){
    document.write('<img src="'+theImages[whichImage]+'"/></a><img src="'+theImages[whichImage+16]+'"/></a></div>');
    }
    I think this has some effect, can somebody tell me the proper number I should use for this?
    Code:
    var whichImage = Math.round(Math.random()*(p-5));

    Please help. Thanks.
    Reply With Quote
      #2  
    Old 02-09-2010, 12:53 PM
    Fang's Avatar
    Fang Fang is offline
    Resistance is futile
     
    Join Date: Apr 2003
    Location: Netherlands
    Posts: 20,058
    Code:
    var whichImage = Math.round(Math.random()*(p/2));
    __________________
    At least 98% of internet users' DNA is identical to that of chimpanzees
    Reply With Quote
      #3  
    Old 02-09-2010, 01:00 PM
    Trfsorz Trfsorz is offline
    Registered User
     
    Join Date: Feb 2010
    Posts: 2
    Quote:
    Originally Posted by Fang View Post
    Code:
    var whichImage = Math.round(Math.random()*(p/2));
    Thanks a lot. That worked out just fine.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 01:15 PM.



    Acceptable Use Policy

    Internet.com
    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.