Archive for glbscripts.myfreeforum.org Forum dedicated to Greasemonkey Scripts made for Goal Line Blitz online game.
 



       glbscripts.myfreeforum.org Forum Index -> Problems and Support
dudeamis

coding help

hey guys and serenity, I'm trying to write a function that loops through a list of arrayed names, and for each name looks at a different array for specific information.

ie, (code not perfect)

var Name = new Array ("Tom", "Dick", "Harry");

var Pos1= new Array ("QB", "RB")
var Pos2= new Array ("RB,"FB")
var Pos3= new Array ("RB")

So basically I want a function that will go through the Name array, and for each name look at Pos1 for Name[1], Pos2 for Name[2], etc and then let the innerHTML of a div=the div's innerHTML + Name[x] + "<br>"; where x is the number of the name array where it found the position I was looking for.

so if I do a QB search it should look like:

Tom

and a RB search would look like:

Dick
Harry

thanks in advance.
pabst

Something like this should be close.  I can't do anything about getting the div until I know what page you're working with.

Code:

var Name = [];
var Pos = [];

function main() {
    addPlayer("Tom",["QB","RB"]);
    addPlayer("Dick",["RB","FB"]);
    addPlayer("Harry",["FB"]);
}

function addPlayer(name, positionArray) {
    var idx = Name.indexOf(name);
    if (idx == -1) {
        idx = Name.length;
        Name.push(name);
        Pos.push(positionArray);
    }
    else {
        Pos[idx] = positionArray;
    }
    return idx;
}

function searchPositions(p) {
    var result = [];
    for (var idx=0; idx<Pos.length; idx++) {
        if (Pos[idx].indexOf(p) != -1) {
            result.push(Name[idx]);
        }
    }
    return result;
}

dudeamis

thanks!

okay something like this

<div>
<img src="QB.gif" onclick="ListTheQBs()">
</div>

<div>
<img src="RB.gif" onclick="ListTheRBs()">
</div>

<div id="PlayerByPositionList">
</div>

so that when I click on one of the gifs I get a list of players who have that position.
mw54finest

lol at the names. Very Happy
pabst

For my table sorting, I do this stuff.  Not sure how it might help you if you're hard coding the HTML but it's here in case its useful.
Code:

//this code checks a row for the stat headings
className = sibling.getAttribute("class");
if (className.match("nonalternating_color2") != null) {
    //when it finds a stat heading, add a click event to it
    sibling.addEventListener("click",sortEvent,true);
    rows++;
}


The event handler is most likely what you'll need.  Not being an HTML guru, I'm not sure if the evt variable gets passed automatically the way your page is written (I would assume it does).
Code:

function sortEvent(evt) {
    //evt.target tells me which element was clicked
    //I need to use 2 parentNode references to go up the page to find what table it belongs to
    sortTable(evt.target.parentNode.parentNode,evt.target.cellIndex);
    return true;
}

       glbscripts.myfreeforum.org Forum Index -> Problems and Support
Page 1 of 1
Create your own free forum | Buy a domain to use with your forum