PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, August 22, 2022

[FIXED] How to make dropdown layered navigation in Magento 2

 August 22, 2022     layered-navigation, magento, magento-2.3, magento2     No comments   

Issue

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.


Solution

Please add below js code:

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


Answered By - Amit Saini
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing