Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript image question

    I was wondering if it was possible to get java to display images that have the same name but diff numbers like:

    Soccer***

    Displays;
    Soccer001
    Soccer002
    Soccer003
    Soccer004
    .... So on and so forth.

    Sorry the question isn't worded well lol

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,149
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    Yes, of course. Why do you think otherwise? All your images have different names, and those names may include numerals.

    Be aware that Java and Javascript are entirely different programming languages, in spite of the confusingly similar names.



    It is your responsibility to die() if necessary….. - PHP Manual

  • #3
    New to the CF scene
    Join Date
    Feb 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I Sorry for not being clear lol. My brain wasn't working at the time. What I meant was: Is it possible to get javascript to automatically display all the images with a certain suffix. Example, I want it to display all images with "soccer" at the beginning of its name automatically. Is this possible? And if so how?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,149
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    Suffix or prefix?

    JavaScript cannot access the user's operating system or the Windows registry. So if you mean display all image files in a directory that begin with "soccer", the answer is no.

    What you should do is make an array containing all the relevant files, e.g.
    var myArray = ["soccer001.jpg", "soccer002.jpg", "soccer003.jpg"] // and so on
    and then use script to select the one to be displayed. I assume you do not want to display them all at the same time.

    You can do this using server-side scripting. See:-
    http://www.javascriptkit.com/javatut...rnalphp2.shtml


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • #5
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by stevmusik View Post
    I Sorry for not being clear lol. My brain wasn't working at the time. What I meant was: Is it possible to get javascript to automatically display all the images with a certain suffix. Example, I want it to display all images with "soccer" at the beginning of its name automatically. Is this possible? And if so how?
    It's not clear how you want the images displayed.

    It is possible to do this provided that the script is supplied with the right parameters. This code will display one image at a time in a cycling slideshow.

    The images displayed would be named "soccer1.jpg" - "soccer50.jpg" from the current folder. If any images in the sequence are unavailable, there should be no error.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Test</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
    </head>
    <body>
    <p>
    <img src='soccer1.jpg' id='myImage' alt='image'>
    
    <script type='text/javascript'>
    
    function loadBySuffix( imageId, prefix, startSuffix, ext, limit, delay )
    {
     var pageImage = document.getElementById( imageId ),
         sfx = startSuffix, 
         holder = document.createElement( 'img' ); 
     
     holder.width = 0;
     holder.height = 0;
     
     document.body.appendChild( holder );
     
     holder.onerror = function()
     {
      if( ++sfx > limit )
       sfx = startSuffix;   
         
      setTimeout( function(){ holder.src = prefix + ( sfx ) + ext }, 1 );  
     }
     
     holder.onload = function()
     {    
      pageImage.src = this.src;
      setTimeout( function(){ holder.onerror(); }, delay );
     }
     
     holder.src = prefix + startSuffix + ext;
    }
    
    loadBySuffix( 'myImage', 'soccer', 1, '.jpg', 50, 2000 );
    
    </script>
    </body>
    </html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •