This repository has been archived on 2024-04-05. You can view files and clone it, but cannot push or open issues/pull-requests.
score-tracker/public/scripts/submit.js

78 lines
2.0 KiB
JavaScript
Raw Normal View History

import * as Data from "./data.js";
const sportDropdown = document.getElementById('sport-dropdown');
const seasonDropdown = document.getElementById('year-dropdown');
const genderDropdown = document.getElementById('gender-dropdown');
const divisionDropdown = document.getElementById('division-dropdown');
async function listSports() {
const sportsList = await Data.getSports();
sportsList.forEach(sport => {
const option = document.createElement('option');
option.text = sport.name;
option.value = sport.id;
sportDropdown.appendChild(option);
});
listSeasons();
}
listSports();
async function listSeasons() {
const seasonsList = await Data.getSeasons();
seasonsList.forEach(season => {
const option = document.createElement('option');
option.text = season.year - 1 + "-" + season.year;
option.value = season.id;
seasonDropdown.appendChild(option);
});
}
listSeasons();
async function listGenders() {
genderDropdown.innerHTML = "";
const selectedSportID = sportDropdown.value;
const gendersList = await Data.getGenders(selectedSportID);
gendersList.forEach(gender => {
const option = document.createElement('option');
option.text = (gender.name == "female") ? "Female" : (gender.name == "male") ? "Male" : "";
option.value = gender.name;
genderDropdown.appendChild(option);
});
listDivisions();
}
async function listDivisions() {
divisionDropdown.innerHTML = "";
const selectedSportID = sportDropdown.value;
const selectedGender = genderDropdown.value;
if(!selectedGender) return;
const divisionsList = await Data.getDivisions(selectedSportID, selectedGender);
divisionsList.forEach(division => {
const option = document.createElement('option');
option.text = division.name;
option.value = division.id;
divisionDropdown.appendChild(option);
})
}
sportDropdown.onchange = listGenders;
genderDropdown.onchange = listDivisions;