0

I'm using a Forumotion forum and I'm trying to use a for loop to iterate through the usergroup links and return information found on those pages.

Example:

Group 1: www.site.com/g1-
Group 2: www.site.com/g2-
Group 3: www.site.com/g3-

etc..

In each page, there are several jQuery objects named $('tr[class]:not(.row3) td:nth-child(2)') and I am trying to get all of those objects on each page so I can test a string to see if it matches the text content of any of the jQuery objects. I also want to know the page it came from (starting at g1-).

There's honestly no limit to the amount of groups that my site can have so iteration is the only thing that will work.

This is what I have so far:

var number_of_groups = 3,

  i = 0, j = 0,

  name = "Some Username";


for (; i < number_of_groups; i++) {
  // code block to iterate through groups
  var groupID = i + 1;

  $.get('/g' + groupID + '-', function(group) {
    var members = [];

    $(group).find('tr[class]:not(.row3) td:nth-child(2)').each(function() {
      members.push($(this).text());
    });

    for (; j < members.length; j++) {
      // code block to iterate through grouplist
      if ( name == members[j] ) alert( members[j] + ' was found in /g' + groupID );
    }
  })
}

Note: The string that I'm testing for is in at least one of the pages (I want to know the first page where the text appears).

I'm using a string that I know for a fact is in /g1-, /g2-, and /g3-, but the code above never alerts /g1-; it always does /g3-. I'm so confused as to why. x.x

0 Answers0