JavaScript array.sort() Issue

fusionice

New Member
drafting up a quick listing tool to list local kids baseball teams. Takes a couple of inputs and writes to a text field. There's some validation and whatnot too, but that's out of scope and doesn't seem to be impacting things.Problem is, I'm having trouble figuring out how to "capture" the existing text, add the new inputs and sort the whole lot, before writing the new result to the paragraph element (effectively replacing it). So far I have:\[code\]var LeagueTeams = [];var IndividualTeam = '';LeagueTeams.push(document.forms[0].TeamName.value);LeagueTeams.push(document.getElementById('TeamList')LeagueTeams = LeagueTeams.sort();for (j = 0; j < LeagueTeams.length; j++) { IndividualTeam = LeagueTeams.pop(); IndividualTeam = IndividualTeam + '' + \n; document.forms[0].TeamName.value += IndividualTeam;}\[/code\]What I end up getting is my input, and then an array of my input PLUS the previous contents, with a couple of line breaks. Setting the operator to = instead of =+ stops it from printing to the array at all.i.e.Enter: \[code\]a\[/code\]Text area: \[code\]a\[/code\]Then enter: \[code\]b\[/code\]Text area: \[code\]a ab\[/code\](etc)
 
Top