const locationInputEnter = document.querySelector("#location-search-btn");
const locationInputClick = document.querySelector(".search-btn");
locationInputEnter.addEventListener("keypress", (event) => {
if (event.key === "Enter") {
event.preventDefault();
let cityname = locationInputEnter.value;
locationBasedSearch(cityname);
locationInputEnter.value = ""; // clear input field
}
});
locationInputClick.addEventListener("click", (event) => {
let cityname = locationInputEnter.value;
locationBasedSearch(cityname);
locationInputEnter.value = ""; // clear input field
});
// Location input based search
const locationBasedSearch = async (cityname) => {
const geocodingURL = `http://api.openweathermap.org/geo/1.0/direct?q=${cityname}&limit=${5}&appid=${APIKEY}`;
fetch(geocodingURL)
.then(response => response.json())
.then(response => console.log(response[0], "Helloworld"))
};
const locationInputEnter = document.querySelector("#location-search-btn");
const locationInputClick = document.querySelector(".search-btn");
locationInputEnter.addEventListener("keypress", (event) => {
if (event.key === "Enter") {
event.preventDefault();
let cityname = locationInputEnter.value;
locationBasedSearch(cityname);
locationInputEnter.value = ""; // clear input field
}
});
locationInputClick.addEventListener("click", (event) => {
let cityname = locationInputEnter.value;
locationBasedSearch(cityname);
locationInputEnter.value = ""; // clear input field
});
// Location input based search
const locationBasedSearch = async (cityname) => {
const geocodingURL = `http://api.openweathermap.org/geo/1.0/direct?q=${cityname}&limit=${5}&appid=${APIKEY}`;
fetch(geocodingURL)
.then(response => response.json())
.then(response => console.log(response[0], "Helloworld"))
};