-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
38 lines (32 loc) · 1.33 KB
/
script.js
File metadata and controls
38 lines (32 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
document.addEventListener('DOMContentLoaded', function() {
const searchImg = document.querySelector('img[alt="search"]');
const searchInput = document.querySelector('.search-bar');
const searchResults = document.getElementById('search-results');
searchImg.addEventListener('click', function() {
const query = searchInput.value.trim();
if (query === '') {
searchResults.innerHTML = '<p style="color: red;">Please enter a hotel name to search.</p>';
return;
}
// Display search results below the search bar
searchResults.innerHTML = `<p style="color: green;">Searching for: <strong>${query}</strong></p>`;
});
// Clear search results when input is emptied
searchInput.addEventListener('input', function() {
if (searchInput.value.trim() === '') {
searchResults.innerHTML = '';
}
});
// Also allow search on Enter key
searchInput.addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
searchImg.click();
}
});
// Clear search results when input loses focus and is empty
searchInput.addEventListener('blur', function() {
if (searchInput.value.trim() === '') {
searchResults.innerHTML = '';
}
});
});