-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
39 lines (32 loc) · 1.09 KB
/
script.js
File metadata and controls
39 lines (32 loc) · 1.09 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
39
// everything for search
async function search() {
const searchText = document.getElementById('search-text').value.trim();
if (searchText !== '') {
// Constructing the URL with search query parameters
const paramsString = `?query=${encodeURIComponent(searchText)}`;
const newUrl = `/search/index.html${paramsString}`;
console.log(newUrl)
window.location.href = newUrl;
} else {
// Handle empty search text or provide a default behavior
}
}
// Event listener for search button click
document.getElementById('search-icon').addEventListener('click', (event) => {
event.preventDefault();
search();
});
// works for the keypress enter
document.getElementById('search-text').addEventListener('keypress', async (e) => {
if (e.key === 'Enter') {
search();
}
});
// everything for clicking the movie
async function handleMovieSelection(movieId) {
if (movieId) {
const paramsString = `?query=${movieId}`;
const newUrl = `/movie/index.html${paramsString}`;
window.location.href = newUrl;
}
}