All Ranks Team Calculator
Build Your Team
table#calculator {
table-layout: fixed;
width: 100%;
max-width: 450px;
margin: 0 auto;
border: 2px solid black; /* Style of the border */
}
table#calculator, td, th {
border-bottom: 2px solid black; /* Style of the border */
border-collapse: collapse;
text-align: center;
}
tr.headerRow {
background-color: rgb(0, 0, 2); /* Background color of the header*/
color: white; /* Font color of the header */
/* Font properties of the header */
font-size: 25px;
}
tr.headerRow th {
width: 33%;
padding: 10px 15px 10px 15px;
}
.weightInput, .weightField, .rankSelect, .rankField, .scoreField {
background-color: lightgray; /* Background color of the rows */
color: black; /* Font color of the rows*/
position: relative;
padding: 3px 0px 3px 0px;
width: 90%;
height: 100%;
/* Font properties of the rows */
text-align: center;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 19px;
font-weight: bold;
}
.weightInput, .rankSelect {
border: none;
}
.weightInput:focus, .rankSelect:focus {
outline: none;
}
.scoreField:hover {
cursor: default;
}
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
display: none;
}
tr.teamRow th {
background-color: rgb(0, 0, 2); /* Background color of the team score */
color: rgb(232, 185, 101); /* Font color of the team score */
padding: 12px 0px 12px 0px;
/* Font properties of the team score */
font-size: 30px;
}
// Elements necesseary for the script
var calculatorTable = null;
var rowPrefab = null;
// Constant to determinate how many rows have to be in the table (>= 1)
let numberOfRows = 5;
function insertInputRow(table, rowPrefab) {
if(table != undefined && rowPrefab != undefined) {
// Assume that first child of the table is its body
var body = table.children[0];
body.insertBefore(rowPrefab.cloneNode(true), body.lastElementChild);
}
}
function calculateRowScore(row) {
var score = null;
if(row != undefined) {
// Get elements of the row and check if they exists
var rank = row.getElementsByClassName('rankSelect')[0].value;
if(!rank) return null;
var weight = row.getElementsByClassName('weightInput')[0].value;
if(!weight) return null;
var scoreElement = row.getElementsByClassName('scoreField')[0];
if(!scoreElement) return null;
// Formula of the score (you can modify these values freely)
score = (weight - 80) * 0.5;
switch(rank) {
case 'purple':
score = score;
break;
case 'brown':
score += 10;
break;
case 'black':
score += 20;
break;
case 'blue':
score -= 10;
break;
}
scoreElement.innerHTML = score;
}
return score;
}
function updateTeamScore(table) {
if(table) {
var teamScore = 0;
var allScoresElements = table.getElementsByClassName('scoreField');
if(!allScoresElements) return null;
var scoreDisplay = table.getElementsByClassName('scoreNumber')[0];
if(!scoreDisplay) return null;
for(var i = 0; i < allScoresElements.length; ++i) {
teamScore += parseFloat(allScoresElements[i].innerHTML);
}
scoreDisplay.innerHTML = teamScore;
return true;
}
return null;
}
window.onload = function() {
calculatorTable = document.getElementById('calculator');
// Assign first searched element from 'inputRow' class to our input row prefab variable
rowPrefab = calculatorTable.getElementsByClassName('inputRow')[0];
for(var i = 1; i < numberOfRows; ++i) {
insertInputRow(calculatorTable, rowPrefab);
}
}
RANK | WEIGHT | SCORE |
---|---|---|
Purple Blue Black Brown | 0 | |
TEAM SCORE: 0 |
*Team score must not exceed zero at weigh-in, on the day of event