From 87c799cd8ce5105ad04894c5f92c3517065e93ba Mon Sep 17 00:00:00 2001 From: Darshanbm05 Date: Sun, 30 Nov 2025 12:26:41 +0530 Subject: [PATCH] handling empty search --- script.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/script.js b/script.js index f5dc616e2..8582fea5b 100644 --- a/script.js +++ b/script.js @@ -71,11 +71,21 @@ searchForm.addEventListener("submit",(e) => { const searchText = document.getElementById("search"); e.preventDefault(); - if (searchText.value == (searchQuery ? searchQuery : "")) { + // Trim whitespace from input + const trimmedValue = searchText.value.trim(); + + // Validate: reject blank or whitespace-only entries + if (trimmedValue === "") { + alert("Please enter a valid search query!"); + return; + } + + // Check if search query is the same as current query + if (trimmedValue === (searchQuery ? searchQuery : "")) { return; } - window.location = `/index.html?s=${searchText.value}`; + window.location = `index.html?s=${encodeURIComponent(trimmedValue)}`; }) // For contributors list