Solved

jquery for loop

Posted on 2014-04-29
9
199 Views
Last Modified: 2014-05-02
I need to have certain amount images show up where i is in the file name.
 
var maxRows = this.NoOfPages;  << here I have a total lets say max total is 6.

how can I add a for loop to add six images and using the [i] at the end of this.filename to appear. 1,2,3,4,5,6

Open in new window

 $("#stack").append($("<img>",
                            {
                                stack: "true",
                                src: "http://ing.com/" + this.FilePath + '/' + this.FileName[i],
                              Style: "width: 600px; height: 750px; z-index: 0; margin-left:auto; margin-right:auto; border: 5px solid rgb(255, 255, 255); box-shadow: 0px 0px 5px rgb(85, 85, 85)"
                            }));

Open in new window

0
Comment
Question by:sevensnake77
  • 5
  • 4
9 Comments
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
Not sure I understand what you mean?

What are you trying to do with the append I am not familiar with that syntax?

According to the docs you can submit multiple parameters to append but they should ultimately all end up as DOM objects.

When you say you want to append the i to the filename - do you mean like this

filename.jpg => filename1.jpg

Or like this

filename.jpg => filename.jpg1

Or are your filenames formatted differently - if so can you give some examples.
0
 
LVL 9

Author Comment

by:sevensnake77
Comment Utility
Well you are somewhat correct, I want to append the count but if the count is 6 then I want to have 6 images.  
The image names would be

filename1.jpg
filename2.jpg
filename3.jpg
filename4.jpg
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
but if the count is 6 then I want to have 6 images
I understood that - just needed to know where you were expecting to append the count to filename or filename string - you answered that above.

Also need to know what you expect from this statemet
$("#stack").append($("<img>",
  {
    stack: "true",
    src: "http://ing.com/" + this.FilePath + '/' + this.FileName[i],
    Style: "width: 600px; height: 750px; z-index: 0; margin-left:auto; margin-right:auto; border: 5px solid rgb(255, 255, 255); box-shadow: 0px 0px 5px rgb(85, 85, 85)"
  }));

Open in new window

It does not look valid - I have not seen .append() used in this way before - can you elaboarate on what you are expecting the result from this to be.
0
 
LVL 9

Author Comment

by:sevensnake77
Comment Utility
$("#stack").append($("<img>",
  {
    stack: "true",
    src: "http://ing.com/" + this.FilePath + '/' + this.FileName[i],
    Style: "width: 600px; height: 750px; z-index: 0; margin-left:auto; margin-right:auto; border: 5px solid rgb(255, 255, 255); box-shadow: 0px 0px 5px rgb(85, 85, 85)"
  }));

Open in new window

The statement above will be
<img src="filename1" />
<img src="filename2" />
<img src="filename3" />
<img src="filename4" />
<img src="filename5" />
<img src="filename6" />

Open in new window

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
Still confused about this part
$("#stack").append($("<img>",
  {
    stack: "true",
    src: "http://ing.com/" + this.FilePath + '/' + this.FileName[i],
    Style: "width: 600px; height: 750px; z-index: 0; margin-left:auto; margin-right:auto; border: 5px solid rgb(255, 255, 255); box-shadow: 0px 0px 5px rgb(85, 85, 85)"
  }));

Open in new window

Do you have any references that documents the above usage of the .append() method. I have tried it in test code and it does not work.

Always interested to learn more - so if you can point me to where you found this code or where there is a description of this use of .append - that would be a good first step.
0
 
LVL 9

Author Comment

by:sevensnake77
Comment Utility
how about lets keep it simple. create an array in jquery
example
var max = 6
I need to have array 1 2 3 4 5 6 in a loop or for each.
you have example of this.
0
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 500 total points
Comment Utility
I know what you want to do just trying to understand how you want to do it.

Here is a simple example
<!doctype html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
var maxRows = 6;
var path = "path_to_file/";
var filename="image";
$(function() {
  for(i=1;i<=6;i++)
  {
    src = "http://ing.com/" + path + filename + i + '.jpg';
    $('#stack').append($('<img/>').attr('src', src));
  }
});
</script>
<style type="text/css">
</style>
</head>
<body>
<div id="stack"></div>
</body>
</html>

Open in new window

0
 
LVL 9

Author Closing Comment

by:sevensnake77
Comment Utility
thanks for your time and patience
0
 
LVL 51

Expert Comment

by:Julian Hansen
Comment Utility
You are welcome - thanks for the points.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now