When I write something in the input and then press search I want to get the title from movies that has that word in it, how do I do that? Im using the omdb API. For example if I search for "Batman" I want to get all the movies titles that has "Batman" in it. Now when I search Batman I only get one Batman movie.
document.getElementById("getForm").addEventListener("submit", (e) => {
e.preventDefault();
loadMovies(document.querySelector("input[name='query']").value);
});
function loadMovies(name) {
var omdbAPI = new XMLHttpRequest();
var omdbURL = `http://www.omdbapi.com/?t=${name.replace(" ", "%20")}&type=movie&apikey=`;
omdbAPI.open("get", omdbURL, true);
omdbAPI.onload = function(event) {
event.preventDefault();
if (this.status == 200) {
var result = JSON.parse(this.responseText);
console.log(result);
var output = "";
output +=
'<div class="user">' +
'<h3>Titel: ' + result.Title + '</h3>' +
'<p>Year: ' + result.Year + '</p>' +
'</div>';
document.getElementById('result').innerHTML = output;
} else {
alert("No results");
}
}
omdbAPI.send();
}
<form action="" method="get" id="getForm">
Movie: <input type="text" name="query">
<button type="submit">Search</button>
</form>
<div id="result">
</div>