Skip to content

Instantly share code, notes, and snippets.

@YuraKolesnikov
Created July 7, 2019 16:38
Show Gist options
  • Save YuraKolesnikov/928f6f4e6014aa87c36a9ff88843880e to your computer and use it in GitHub Desktop.
Save YuraKolesnikov/928f6f4e6014aa87c36a9ff88843880e to your computer and use it in GitHub Desktop.
Select on change fetch
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<select name="category" id="category-select">
<option value="" disabled selected>Please select the category</option>
<option value="tv">TV</option>
<option value="computers">Computers</option>
<option value="phones">Phones</option>
<option value="games">Videogames</option>
</select>
<script>
const categorySelect = document.getElementById('category-select')
categorySelect.addEventListener('change', e => {
const currentCategory = e.target.value
/* Вот здесь пойдет запрос на бэкенд, посылаешь currentCategory */
console.log(currentCategory)
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment