Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.1 kB
2
Indexable
Never

<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);
Leave a Comment