| View previous topic :: View next topic |
| Author |
Message |
dudeamis Developer
Joined: 08 Jul 2008 Posts: 13
|
Posted: Tue Jul 29, 2008 7:05 am Post subject: 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.
|
|
| Back to top |
|
 |
pabst Developer
Joined: 23 Jun 2008 Posts: 235
|
Posted: Tue Jul 29, 2008 2:34 pm Post subject: |
|
|
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;
}
|
|
|
| Back to top |
|
 |
dudeamis Developer
Joined: 08 Jul 2008 Posts: 13
|
Posted: Thu Jul 31, 2008 5:12 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
mw54finest Site Admin

Joined: 22 Jun 2008 Posts: 160
|
Posted: Thu Jul 31, 2008 8:18 am Post subject: |
|
|
lol at the names.  _________________ Eat, Sleep, Live GLB! |
|
| Back to top |
|
 |
pabst Developer
Joined: 23 Jun 2008 Posts: 235
|
Posted: Thu Jul 31, 2008 9:03 pm Post subject: |
|
|
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;
}
|
|
|
| Back to top |
|
 |
|