Solved

jquery for loop

Posted on 2014-04-29
9
205 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 40030672
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
ID: 40032041
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 57

Expert Comment

by:Julian Hansen
ID: 40032598
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
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!

 
LVL 9

Author Comment

by:sevensnake77
ID: 40034529
$("#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
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 40035098
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
ID: 40035365
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 57

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 40036550
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
ID: 40037678
thanks for your time and patience
0
 
LVL 57

Expert Comment

by:Julian Hansen
ID: 40037861
You are welcome - thanks for the points.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

724 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