From c542d55ad6580f99eb16315be3b22d137051e7ce Mon Sep 17 00:00:00 2001 From: ShadowFax <55938330+ShadowFax1731@users.noreply.github.com> Date: Wed, 24 Jul 2024 11:40:55 +0530 Subject: [PATCH] Updated the div element as a form for search --- .../javascript/src/challenges/weather-app/index.html | 4 ++-- apps/javascript/src/challenges/weather-app/index.js | 12 +++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/apps/javascript/src/challenges/weather-app/index.html b/apps/javascript/src/challenges/weather-app/index.html index 60faf79b5..17b6867d7 100644 --- a/apps/javascript/src/challenges/weather-app/index.html +++ b/apps/javascript/src/challenges/weather-app/index.html @@ -8,10 +8,10 @@

CHECK THE WEATHER!!

- +

INVALID CITY NAME!!!

diff --git a/apps/javascript/src/challenges/weather-app/index.js b/apps/javascript/src/challenges/weather-app/index.js index 0eada55ab..b209d7af8 100644 --- a/apps/javascript/src/challenges/weather-app/index.js +++ b/apps/javascript/src/challenges/weather-app/index.js @@ -62,13 +62,7 @@ searchBtn.addEventListener('click', () => { checkWeather(searchBox.value); }); -//select the search area and the enter press event listener to it. -const searchDiv = document.querySelector('.search'); - -searchDiv.addEventListener('keypress', function (event) { - //check MDN Reference for more on this but the event sends a key named "key" with the value as 'Enter' - if (event.key === 'Enter') { - event.preventDefault(); - checkWeather(searchBox.value); - } +document.querySelector('form').addEventListener('submit', (e) => { + e.preventDefault(); + checkWeather(searchBox.value); });