Like this code

const form = document.querySelector('form'); form.addEventListener('submit', () => { const checkboxes = form.querySelectorAll('input[type="checkbox"]'); const query = [...checkboxes] .filter(checkbox => checkbox.checked) .map(checkbox => checkbox.name) .join('+') const url = 'https://example.ru/search/' + query; // not working in sandbox // window.location.href = url; alert('redirect to ' + url); }) 
 <form> <input type="checkbox" name="Москва"><label>Москва</label> <input type="checkbox" name="Лондон" value="Лондон"><label>Лондон</label> <input type="checkbox" name="Париж" value="Париж"><label>Париж</label> <input type="checkbox" name="Вашингтон" value="Вашингтон"> <label>Вашингтон</label> <button>Подобрать</button> </form> 

Redo on select option Naturally the question relates to JS

    1 answer 1

     const form = document.querySelector('form'); form.addEventListener('submit', (e) => { e.preventDefault(); const options = form.country.querySelectorAll('option'); const url = 'https://example.ru/search/'; for (var n = 0; n < options.length; n++) { if (options[n].selected == true) alert('redirect to ' + url + options[n].value); } }) 
     <form> <select name="country"> <option value="Москва">Москва</option> <option value="Лондон">Лондон</option> <option value="Париж">Париж</option> <option value="Вашингтон">Вашингтон</option> </select> <button>Подобрать</button> </form> 

    • And if I have 2 select? - Ilya
    • more specifically, specify what you want to get from 2 select - sergey - dev
    • There is a country and a city. There are coherent selekta, a person chose a country and chose a city after he clicked on the url button became country + city If he chose only the country, then only the country in the url is Ilya