<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<form id="film-form">
<label for="title">Название:</label><br>
<input type="text" id="title" name="title"><br>
<label for="genre">Жанр:</label><br>
<input type="text" id="genre" name="genre"><br>
<label for="releaseYear">Год:</label><br>
<input type="text" id="releaseYear" name="releaseYear"><br>
<input type="checkbox" id="isWatched" name="isWatched">
<label for="isWatched">Успели посмотреть?</label><br>
<input type="submit" value="Submit">
</form>
<div id="form-select-del">
<div id="change-form">
<input class="NameFilm" placeholder="Название фильма">
<input class="GenreFilm" placeholder="Жанр">
<input class="YearReleaseFilm" placeholder="Год релиза">
<select id="city" name="city">
<option class="option_1" value="" disabled selected>-- Выберите --</option>
<option class="option_2">Все</option>
<option class="option_3">Да</option>
<option class="option_4">Нет</option>
</select>
<button class="delAll">Удалить всё</button>
</div>
</div>
<table id="film-table">
<thead>
<tr>
<th>Название</th>
<th>Жанр</th>
<th>Год</th>
<th>Успели посмотреть?</th>
<th>Действие</th>
</tr>
</thead>
<tbody id="film-tbody">
<!-- Rows will be inserted here -->
</tbody>
</table>
<script src="script.js"></script>
</body>
</html>
const isWatched = document.querySelector('#city');
isWatched.addEventListener('change', async (event) => {
const target = event.target.value;
const GET = await fetch(`https://sb-film.сс/films`, {
method: "GET",
headers: {
"Content-Type": "application/json",
email: "ovikdevil@gmail.com",
}
});
let X = await GET.json();
function filterByPrefix(X, target) {
if(target === 'Да') {
return X.filter(item =>
item.isWatched == true
)};
if(target ==='Нет') {
return X.filter(item =>
item.isWatched == false
)};
if(target === 'Все'){
return X
}
}
let sort = filterByPrefix(X , target);
console.log(sort)
const filmTableBody = document.getElementById("film-tbody");
filmTableBody.innerHTML = '';
sort.forEach((film, index) => {
let Filter = document.createElement("tr");
Filter.innerHTML = `
<td>${film.title}</td>
<td>${film.genre}</td>
<td>${film.releaseYear}</td>
<td>${film.isWatched ? "Да" : "Нет"}</td>
`;
filmTableBody.append(Filter);
})});
Почему при выборе нужного Option происходит автообновление страницы и фильтрация не срабатывает?
Вернее, она срабатывает, но на странице происходит автообновление и значения записываются старые, не отфильтрованные.