spacex / public /static /index.js
alamin655
Update search functionality with improved code
5689d37 unverified
raw
history blame
626 Bytes
/**
* Selects the input element for the search box
* @type {HTMLInputElement}
*/
const searchBox = document.querySelector('input');
/**
* Redirects the user to the search results page with the query parameter
*/
function searchWeb() {
const query = searchBox.value.trim();
if (query) {
window.location.href = `search?q=${encodeURIComponent(query)}`;
}
}
/**
* Listens for the 'Enter' key press event on the search box and calls the searchWeb function
* @param {KeyboardEvent} e - The keyboard event object
*/
searchBox.addEventListener('keyup', (e) => {
if (e.key === 'Enter') {
searchWeb();
}
});