First I need to create an array with the player's name taken from the input #P1 and #P2 and #P3.
Example: Using members[class] look up standing[code] and place standing[rank] into an added numeric field in the array.
Sort the array by [rank] and [name].
Output a delimited file called "players.txt" ---> "Paul|Jim|Bob" THIS PART IS MISSING FROM THE JS BELOW. HOW CAN I WRITE TO PLAYERS.TXT ?
HTML: (the html code with the player's name [#P1] and class [Y1])
<div class="block">
<div class="line"><input type = "text" id = "P1" name = "N1" /></div>
<div class="line"><input type = "text" id="Y1"></div>
</div> <br />
<div class="block">
<div class="line"><input type = "text" id = "P2" name = "N2" /></div>
<div class="line"><input type = "text" id="Y2"></div>
</div> <br />
<div class="block">
<div class="line"><input type = "text" id = "P3" name = "N3" />
<div class="line"><input type = "text" id="Y3"></div>
</div> <br />
JSON:
<script>
var members = [
{"Class": "A", "Name": "Paul"},
{"Class": "C", "Name": "Jim"},
{"Class": "B", "Name": "Bob"},
];
</script>
<script>
var standing = [
{"code" : "A", "rank" : "1"},
{"code" : "B", "rank" : "2"},
{"code" : "C", "rank" : "3"},
];
</script>
JS:
var memberstosort = [], sorted = [];
function sort() {
memberstosort.sort(function(l, r) { return l.rank - r.rank});
Object.keys(memberstosort).map(function(objectKey, index) {
var value = memberstosort[objectKey].name;
sorted.push(value);
});
sorted = sorted.join('|');
document.getElementById('result').innerHTML = sorted;
}
var currentname, currentclass, index, currentrank;
function fillClass(id) {
currentname = document.getElementById(id).value;
index = members.findIndex(checkClass);
currentclass = members.filter(checkClass).length ?
members.filter(checkClass)[0].Class : null;
if (currentclass) {
currentrank = standing.filter(checkRank).length ?
standing.filter(checkRank)[0].rank : null;
} else {
return;
}
var currentmember = {};
currentmember.name = currentname;
currentmember.rank = currentrank;
memberstosort.push(currentmember);
}
function checkClass(player) {
return player.Name.toLowerCase() === currentname.toLowerCase();
}
function checkRank(standing) {
return standing.code === currentclass;
}