diff --git a/public/scripts/submit.js b/public/scripts/submit.js index 85fc410..678fa16 100644 --- a/public/scripts/submit.js +++ b/public/scripts/submit.js @@ -10,21 +10,9 @@ 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() { + seasonDropdown.innerHTML = ""; + const seasonsList = await Data.getSeasons(); seasonsList.forEach(season => { @@ -36,18 +24,36 @@ async function listSeasons() { } listSeasons(); +async function listSports() { + sportDropdown.innerHTML = ""; + + const sportsList = await Data.getSports(); + + sportsList.forEach(sport => { + const option = document.createElement('option'); + option.text = sport.name; + option.value = sport.id; + sportDropdown.appendChild(option); + }); + + listGenders(); +} +listSports(); + 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); - }); + if(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(); } @@ -58,16 +64,16 @@ async function listDivisions() { const selectedSportID = sportDropdown.value; const selectedGender = genderDropdown.value; - if(!selectedGender) return; + if(selectedGender) { + const divisionsList = await Data.getDivisions(selectedSportID, selectedGender); - 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); - }) + divisionsList.forEach(division => { + const option = document.createElement('option'); + option.text = division.name; + option.value = division.id; + divisionDropdown.appendChild(option); + }); + } }