function displayPicture() question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pr1nnyraid
    New Member
    • Dec 2009
    • 7

    function displayPicture() question

    Hey guys, I'm trying to make a function that will display a group of similarly named images. So far my js looks like this, the script is awful but the general idea is still present. I want the titles to display in order from 1 to 21. title1.jpg ,title2.jpg, title3.jpg , etc.
    Is this even possible? or are there any better ways to accomplish this?
    I've never done this before but i do know some javascript.
    Thanks for all the responses in advance. You guys are geniuses.

    Code:
    <script type="text/javascript">
    function displayPicture()
    {
          var imgNum ="title"+""+".jpg"+"<br />"
          var imgMax = 21
          if imgNum < imgMax,imgNum++,
          <img src = imgNum height="" width=''">
    }
    </script>
    Last edited by Dormilich; Mar 9 '10, 02:36 PM. Reason: Please use [code] tags when posting code
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    There are n no. of ways to do this. The way you have specified. It's a method we can do. But your code should be tuned.

    Code:
    <script type="text/javascript">
    function displayPicture()
    {
    var imgStr="";
    var imgMax = 21
    for(var i=1;i<-imgMax;i++)
      imgStr+="<img src='title"+i+".jpg' height='' width='' /> <br/>";
    }
    </script>

    Comment

    • Pr1nnyraid
      New Member
      • Dec 2009
      • 7

      #3
      hmmm

      hmmm the code is still broken....and my validator isn't returning any errors
      I made one change to the function you provided, because title's are inside another directory called "maps".... I'm not sure if the root file should be included or not
      <img src='maps/title"+i...

      Code:
       
      <script type="text/javascript">
        function displayPicture()
         {
         var imgStr="";
         var imgMax = 21
         for(var i=1;i<-imgMax;i++)
         imgStr+="<img src='maps/tit"+i+".jpg' height='200' width='200' /> <br/>";
         }
         </script>
      Last edited by Pr1nnyraid; Mar 9 '10, 11:01 PM. Reason: Fixed it... Thanks for the help Ramanan

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        Originally posted by Pr1nnyraid
        Code:
         <script type="text/javascript">
          function displayPicture()
           {
           var imgStr="";
           var imgMax = 21
           for(var i=1[B];i<-imgMax[/B];i++)
           imgStr+="<img src='maps/tit"+i+".jpg' height='200' width='200' /> <br/>";
           }
           </script>
        should be
        Code:
         <script type="text/javascript">
        function displayPicture()
        {
            var i, imgStr = "",
                imgMax = 21;
            for (i = 1; i <= imgMax; i++) {
                imgStr += "<img src='maps/tit" + i + ".jpg' height='200' width='200' /> <br/>";
            }
            return imgStr;
        }
        // somewhere else
        // [I]container[/I] is the element, where the image string should be pasted
        [I]container[/I].innerHTML = displayPicture();
        </script>

        Comment

        • RamananKalirajan
          Contributor
          • Mar 2008
          • 608

          #5
          Yep Dormilich, It's a typography error. It wont happen again.

          Thanks and Regards
          Ramanan Kalirajan

          Comment

          • Pr1nnyraid
            New Member
            • Dec 2009
            • 7

            #6
            I fixed almost immediately after my second post. It works great now.At first I didn't think to add in another variable "i" but Ramanan cleared that up. Everytime I post here I'm always surprised at the quick responses and the level of programming skill you guys have.

            Comment

            Working...