-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscriptsearch.js
40 lines (31 loc) · 1.22 KB
/
scriptsearch.js
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
40
document.addEventListener('DOMContentLoaded', function () {
const searchForm = document.getElementById('search-form');
const searchInput = document.getElementById('search-input');
const searchResults = document.getElementById('search-results');
const urlParams = new URLSearchParams(window.location.search);
const query = urlParams.get('query');
if (query) {
searchInput.value = query;
displaySearchResults(query);
}
searchForm.addEventListener('submit', function (e) {
e.preventDefault();
const query = searchInput.value.trim();
if (query) {
window.location.href = `search.html?query=${encodeURIComponent(query)}`;
}
});
function displaySearchResults(query) {
searchResults.innerHTML = `<p>You searched for: <strong>${query}</strong></p>`;
searchResults.innerHTML += `
<div>
<h3>Result 1</h3>
<p>This is a result based on the query: ${query}</p>
</div>
<div>
<h3>Result 2</h3>
<p>This is another result for the query: ${query}</p>
</div>
`;
}
});