I would like that I can choose brand 1 and brand 2 and brand 3.
Is it possible that I can choose multipe options from a dropdown list without pressing “strg”? Just by clicking? Like a checkbox listed as a dropdown menu? And that the option values are just joined in the url: brand1,2,3
<form action="" method="GET" id="myForm">
<select name="channel" id="0" onChange="changeURL()">
<option value="" selected disabled>Choose Channel</option>
<option value="facebook-ads">Facebook ads</option>
<option value="instagram-ads">Instagram ads</option>
</select>
<select name="brand" id="1" onChange="changeURL()">
<option value="" selected disabled>Choose Brand</option>
<option value="brand-1">brand 1</option>
<option value="brand-2">brand 2</option>
<option value="brand-3">brand 3</option>
</select>
</form>
<p id="test"></p>
<script>
// Initialize the filters array
var filters = [];
// Initialize filters with any pre-selected values on page load
document.addEventListener("DOMContentLoaded", function() {
// Get all select elements
var selects = document.querySelectorAll('select');
// Initialize the filters array with the correct size
filters = new Array(selects.length).fill("");
// Check for any pre-selected options
selects.forEach(function(select) {
if (select.selectedIndex > 0) { // If something is selected (not the disabled option)
filters[select.id] = select.value;
}
});
// Update URL on initial load
changeURL();
});
function changeURL() {
var yourUrl = "https://yourdomain.com"; // Base URL
var queryParams = [];
// Update the current changed value
var selects = document.querySelectorAll('select');
selects.forEach(function(select) {
filters[select.id] = select.value;
});
// Build query parameters, only including valid values
selects.forEach(function(select) {
var paramName = select.name;
var paramValue = filters[select.id];
// Only add to URL if there's a valid value
if (paramValue && paramValue !== "" && paramValue !== "undefined") {
queryParams.push(paramName + "=" + paramValue);
}
});
// Add the query string if we have parameters
if (queryParams.length > 0) {
yourUrl += "?" + queryParams.join("&");
}
// Display the result
document.getElementById("test").innerHTML = yourUrl;
}
</script>
Thank you in advance for your help!