• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 209
  • Last Modified:

jquery for loop

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
Seven price
Asked:
Seven price
  • 5
  • 4
1 Solution
 
Julian HansenCommented:
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
 
Seven priceFull StackAuthor Commented:
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
 
Julian HansenCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Seven priceFull StackAuthor Commented:
$("#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
 
Julian HansenCommented:
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
 
Seven priceFull StackAuthor Commented:
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
 
Julian HansenCommented:
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
 
Seven priceFull StackAuthor Commented:
thanks for your time and patience
0
 
Julian HansenCommented:
You are welcome - thanks for the points.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now