Untitled

 avatar
unknown
plain_text
a year ago
1.1 kB
5
Indexable

<script>
    // Get references to the dropdowns
    var positionsDropdown = document.getElementById('positions');
    var candidatesDropdown = document.getElementById('candidates');
    
    // Function to populate candidates based on selected position
    function populateCandidates() {
        // Clear existing options
        candidatesDropdown.innerHTML = '';
        
        // Get the selected position
        var selectedPosition = positionsDropdown.value;
        
        // Get the candidates for the selected position
        var candidates = Object.keys(votes[selectedPosition]);
        
        // Add options to the candidates dropdown
        candidates.forEach(function(candidate) {
            var option = document.createElement('option');
            option.textContent = candidate;
            candidatesDropdown.appendChild(option);
        });
    }
    
    // Call populateCandidates initially
    populateCandidates();
    
    // Add event listener to positions dropdown to call populateCandidates when selection changes
    positionsDropdown.addEventListener('change', populateCandidates);
Editor is loading...
Leave a Comment