Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- window.addEventListener("DOMContentLoaded", function(e) {
- let typeSelect = document.querySelector("select[name='tip']");
- let areaSelect = document.querySelector("select[name='pa_rajon']");
- let roomSelect = document.querySelector("select[name='kolichestvo-komnat']");
- function makeEmptyOption(value, text) {
- let el = document.createElement("option");
- el.value = value;
- el.text = text;
- return el
- }
- typeSelect.add(makeEmptyOption("", "-"), typeSelect.options[0]);
- roomSelect.add(makeEmptyOption("", "-"), roomSelect.options[0]);
- areaSelect.add(makeEmptyOption("", "-"), areaSelect.options[0]);
- const searchParams = new URLSearchParams(window.location.search);
- let typeParam = searchParams.get("tip");
- let roomParam = searchParams.get("kolichestvo-komnat");
- let areaParam = searchParams.get("pa_rajon");
- console.log("typeParam", typeParam);
- console.log("roomParam", roomParam);
- console.log("roomParam", roomParam);
- function checkIfEmptyParam(param) {
- return param === ""
- }
- function setSelectedOption(el, idx) {
- el.options.selectedIndex = idx;
- }
- console.log("checkIfEmptyParam(typeParam)", checkIfEmptyParam(typeParam));
- console.log("checkIfEmptyParam(roomParam)", checkIfEmptyParam(roomParam));
- if (location.pathname === "/shop/") {
- setSelectedOption(typeSelect, 0);
- setSelectedOption(roomSelect, 0);
- setSelectedOption(areaSelect, 0);
- } else {
- checkIfEmptyParam(typeParam) ? setSelectedOption(typeSelect, 0) : null;
- checkIfEmptyParam(roomParam) ? setSelectedOption(roomSelect, 0) : null;
- checkIfEmptyParam(areaParam) ? setSelectedOption(areaSelect, 0) : null;
- }
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement