erwinson francisco
erwinson francisco

Reputation: 1

How to make a drop down filter for genre from OMDB API that is auto populated

Genre Drop Down is not getting populated by OMDB unlike when I used TMDB here is my Java Script for your checkingL

function fetchGenres() {
    const url = `http://www.omdbapi.com/?apikey=8dc88624`;

    fetch(url)
    .then(response => response.json())
    .then(data => {
        const genreDropdown = document.getElementById('genre');
        genreDropdown.innerHTML = '';
        const genres = data['genres'];
        genres.forEach(genre => {
            const option = document.createElement('option');
            option.value = genre;
            option.textContent = genre;
            genreDropdown.appendChild(option);
        });
    })
    .catch(error => console.error('Error fetching genres:', error));
}

I tried with other Movie Database like TMDB and the genre filter is getting populated but we are specifically tasked by our teacher to use OMDB.

Upvotes: 0

Views: 68

Answers (0)

Related Questions