Forum Moderators: open
var captains = new Array();
captains[0] = 'Dave Busch,DaveB,5280534';
captains[1] = 'Gary Bushman,GaryB,5280698';
captains[2] = 'Gary Fox,GaryF,2979466';
captains[3] = 'Rick Fritzmeier,RickF,5280761';
captains[4] = 'Freddy Gallego,FreddyG,5280687';
captains[5] = 'Lee Handley,LeeH,5280723';
captains[6] = 'Ray Harrison,RayH,5280549';
captains[7] = 'Paul Kolarik,PaulK,5280606';
captains[8] = 'Gary Luiz,GaryL,5280783';
captains[9] = 'Rob Maxey,RobM,5280711';
captains[10] = 'Arthur Owings,ArthurO,5280734';
captains[11] = 'Dane Owings,DaneO,5280749';
captains[12] = 'Robert Raffaelli,RobertR,5145685';
captains[13] = 'Stephen Scholz,StephenS,5280622';
captains[14] = 'David Sirsi,DavidS,5280561';
captains[15] = 'Jesse Smith,JesseS,5145685';
captains[16] = 'Ted Smith,TedS,5280590';
captains[17] = 'Robert Tom,RobertT,5280777';
captains[18] = 'Brian Wiese,BrianW,5280574';
for (var i=0; i<captains.length; i++) {
var captain = captains[i].split(',');
var captainLast = captain[0].split(' ');
document.write ('<td><span style="font-size: 1.2em; font-weight: bold; text-decoration: underline;">' + captainLast[1] + ' Team</span><br /><a href="' + captain[2] + '">' + captain[0] + '</a>' + addPlayers() + '</td>');
if ((i==3)¦(i==7)¦(i==11)¦(i==15)¦(i==19)) {
document.write ('</tr><tr><td colspan="4"> </td></tr><tr>');
}
}
var players = new Array();
players[0] = 'LeeH,Don Jacobs,DonJ,';
function addPlayers(thisPlayer) {
for (var j=0; j<players.length; j++) {
var player = players[i].split(',');
if (thisPlayer==player[0]) {
document.write ('<br /><a href="' + player[3] + '">' + player[1] + '</a><br />');
}
}
}
var playersthrough the end of the
addPlayersfunction above the
for()loop, it should work.
Added: document.write is a funny thing because it has to execute immediately, so it throws off a lot of patterns that would otherwise work if you were doing regular DOM manipulation.
Right, try this:
if ( i==3 ¦¦
i==7 ¦¦
i==11 ¦¦
i==15 ¦¦
i==19) { Ironically your way will work but not for the reason you may think!
(also, 'i' will never eaqual 19 at the moment as you only have 18 captains)
Also, I like to define array loops like this, it looks a little neater:
for (var i=0; captains[i]; i++) { A FOR statement is basically 3 commands:
for( start with this; while this; do this) { I think the error is because players is not defined before the addPlayers function is run. Your script will run in the order it is written, your captains loop is jumping to a part of the script where at that point, players is not defined. Imagine it like this:
1. Define captains
2. Loop captains
-> 3. Call addPlayers
4. Define players
You see?
If you move your players array creation immediately after where you define captains that should fix it.
Here's an updated version of my code minus the arrays:
for (var i=0; i<captains.length; i++) {
var captain = captains[i].split(',');
var captainLast = captain[0].split(' ');
var captainID = captain[1];
document.write('<td><span style="font-size: 1.2em; font-weight: bold; text-decoration: underline;">' + captainLast[1] + ' Team</span><br /><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=' + captain[2] + '">' + captain[0] + '</a>' + addPlayers(captainID) + '</td>');
if ((i==3)¦¦(i==7)¦¦(i==11)¦¦(i==15)) {
document.write('</tr><tr><td colspan="4"> </td></tr><tr>');
}
}
function addPlayers(thisPlayer) {
for (var j=0; j<players.length; j++) {
var player = players[j].split(',');
if (thisPlayer==player[0]) {
return '<br /><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=' + player[3] + '">' + player[1] + '</a>';
}
}
return ' ';
}