-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
31 lines (30 loc) · 1.2 KB
/
script.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
document.getElementById('search-button').addEventListener('click', searchByName);
function searchByName() {
const searchValue = document.getElementById('search-box').value.trim();
if (searchValue) {
fetch('/search', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ name: searchValue })
})
.then(response => response.json())
.then(data => {
const resultsDiv = document.getElementById('search-results');
resultsDiv.innerHTML = '';
if (data && data.length > 0) {
data.forEach(item => {
const result = document.createElement('p');
result.textContent = `Name: ${item.Name}, Membership ID: ${item.MembershipID}`;
resultsDiv.appendChild(result);
});
} else {
const noResults = document.createElement('p');
noResults.textContent = 'No results found';
resultsDiv.appendChild(noResults);
}
})
.catch(error => console.error('Error:', error));
}
}