I am using an API for a weather app. But when it comes to create a search bar using a <input type="text">
and a document.getElementById(' ').value
it returns me undefined (when I log it out). So I'm wondering if there is any other way to get the input.
HTML:
<form class="search">
<input type="text" id="Search" name="Search" placeholder="Search city..." style="width: 50%; padding: 10px;">
<button type="submit" id="button" style="padding: 10px;">SEARCH</button>
</form>
JavaScript:
let location1 = document.getElementById('Search').value;
let api1 = 'http://api.openweathermap.org/data/2.5/weather?q=';
let api2 = '&appid=ece23eaa3a8d940b327a0cdc41c1e344&units=metric';
let API = api1 + location1 + api2;
// MAIN WEATHER */
fetch(API) // Current weather API
Any help will be apreciated