diff --git a/index.html b/index.html index ae616da..ae75dad 100644 --- a/index.html +++ b/index.html @@ -312,21 +312,21 @@ body { document.getElementById('searchForm').addEventListener('submit', function(e) { - e.preventDefault(); - const searchQuery = document.querySelector('[name="search"]').value.trim(); - if (searchQuery) { - searchMedia(searchQuery); - } + e.preventDefault(); + const searchQuery = document.querySelector('[name="search"]').value.trim(); + if (searchQuery) { + searchMedia(searchQuery); + } + }); + + function searchMedia(query) { + const url = `https://api.themoviedb.org/3/search/multi?api_key=${apiKey}&query=${encodeURIComponent(query)}`; + fetch(url) + .then(response => response.json()) + .then(data => { + displaySearchResults(data.results, 'searchResults'); }); - - function searchMedia(query) { - const url = `https://api.themoviedb.org/3/search/multi?api_key=${apiKey}&query=${encodeURIComponent(query)}`; - fetch(url) - .then(response => response.json()) - .then(data => { - displaySearchResults(data.results, 'searchResults'); - }); - } + } function displaySearchResults(results, containerSee) { @@ -344,7 +344,7 @@ body { Poster for ${title}

${title}

${overview}

- + `; container.appendChild(movieTile); }