How to make dropdown layered navigation in Magento 2

285 Views Asked by At

I'm figuring out about Magento 2 layered navigation. I want to make this navigation with dropdown lists.

I try this code:

<select onchange="setLocation(this.value)">
 <option value=""><?php echo 'Choose an Option...' ?></option>
 <?php foreach ($this->getItems() as $_item): ?>
     <option
        <?php if ($_item->getCount() > 0): ?>
        value="<?php echo $this->urlEscape($_item->getUrl()) ?>"><?php echo $_item->getLabel() ?>
        <?php else: echo '>' . $_item->getLabel() ?>
        <?php endif; ?>
        (<?php echo $_item->getCount() ?>)
    </option>
<?php endforeach ?>
</select>

but I am getting the error "setLocation(this.value) is not defined". If anyone has another option, please let me know.

1

There are 1 best solutions below

2
Amit Saini On BEST ANSWER

Please add below js code:

function setLocation(value) {
    window.location = value;
}