-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch-restaurant.js
39 lines (31 loc) · 1.49 KB
/
search-restaurant.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
function processSearchInput() {
if (searchRestaurant) {
searchRestaurant.addEventListener('input', async function() {
searchCategory.value = 'all'
const response = await fetch('../database/data-fetching/api-restaurants.php?search=' + this.value)
const restaurants = await response.json()
const section = document.querySelector('#restaurants')
section.innerHTML = ''
for (const restaurant of restaurants) {
const article = document.createElement('article')
const header = document.createElement('header')
const heading = document.createElement('h3')
const link = document.createElement('a')
const paragraph = document.createElement('p')
const img = document.createElement('img')
link.href = 'restaurant-page.php?id=' + restaurant.restaurantID
link.textContent = restaurant.name
heading.appendChild(link)
header.appendChild(heading)
article.appendChild(header)
paragraph.textContent = restaurant.description
article.appendChild(paragraph)
img.src = "../../img/" + restaurant.picture
article.appendChild(img)
section.append(article)
}
})
}
}
const searchRestaurant = document.querySelector('#search-restaurant')
processSearchInput()