SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I think I need another for loop

    Hi . . .

    Currently I am running a for loop:

    for (var a = 1; a < rowNodes.length; a++)
    {
    if (foo == bar)
    {
    <img src='numbers/" + a + "mapPoint.gif'>
    }
    }

    which is working just fine and pulling out the correct rows in a XML file of 500 or so rows.

    I am attaching an image every time there is a match, (which can be every 5 rows or so). I am using the "a" variable to attach the image.

    The problem is that the value of "a" is growing like this: "5, 10, 15, 20, etc.,"
    What I need . . . is for the a value to only increase by the value of "1" every time there is a match from an iteration.

    For the life of me I cannot figure out the solution to this. Is there someone oyt there that can show me how to do this?

    Thx -
    Rob

  2. #2
    SitePoint Wizard
    Join Date
    Dec 2003
    Location
    USA
    Posts
    2,582
    Mentioned
    29 Post(s)
    Tagged
    0 Thread(s)
    If I understand what you are asking, you want a to not actually equal the row number, but be an increment for each image. If that's the case, try something like this:
    Code:
    var b = 0;
    for(var a=1; a < rowNodes.length; a++)
    {
        if(foo==bar)
        {
            <img src='numbers/" + a + "mapPoint.gif'>
            b++;
        }
    }
    Hope that helps.

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This helped a great deal. I have the solution. Very clean and simple (probably why I couldn't see it). Thank you . . .


Bookmarks

Posting Permissions

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