# Redirect to different page and retain selection

**URL:** <https://forum.finsweet.com/t/redirect-to-different-page-and-retain-selection/2139>\
**Category:** General\
**Created:** [November 6, 2023, 4:59pm UTC](https://forum.finsweet.com/t/redirect-to-different-page-and-retain-selection/2139 "2023-11-06T16:59:25Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marc](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/marc/32/1583_2.png) [@Marc](https://forum.finsweet.com/u/Marc)\
**Post date:** [November 6, 2023, 4:59pm UTC](https://forum.finsweet.com/t/redirect-to-different-page-and-retain-selection/2139/1 "2023-11-06T16:59:25Z")

</div>

Hi,

Is this something that can be done?

I have a page which holds CMS Sort and Filter: [Image Suppliers - BAPLA](https://bapla-com.webflow.io/image-suppliers)

What I would want to do now is have basically the same search bar on the [homepage](https://bapla-com.webflow.io), where visitors can search and use the dropdowns and are then being redirected to the first page I mentioned upon submit and retain their selection.

Thanks

---

<div class="post-metadata">

**Author:** ![Support-Luis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/support-luis/32/53_2.png) [@Support-Luis](https://forum.finsweet.com/u/Support-Luis)\
**Post date:** [November 6, 2023, 5:28pm UTC](https://forum.finsweet.com/t/redirect-to-different-page-and-retain-selection/2139/2 "2023-11-06T17:28:28Z")

</div>

Hey @Marc! You check this thread → [Show Search Results on CMS Filter Page from a different page](https://forum.finsweet.com/t/show-search-results-on-cms-filter-page-from-a-different-page/857) on how to do it for the search bar.

If this is the functionality you are looking for, add the dropdowns and let me know so I can jump in and add the missing JS for them 💪

---

<div class="post-metadata">

**Author:** ![Marc](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/marc/32/1583_2.png) [@Marc](https://forum.finsweet.com/u/Marc)\
**Post date:** [November 6, 2023, 5:42pm UTC](https://forum.finsweet.com/t/redirect-to-different-page-and-retain-selection/2139/4 "2023-11-06T17:42:26Z")

</div>

That is looking very promising. But I don’t understand what you mean with “add the dropdowns” and where you are going to add the missing JS then.

---

<div class="post-metadata">

**Author:** ![Support-Luis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/support-luis/32/53_2.png) [@Support-Luis](https://forum.finsweet.com/u/Support-Luis)\
**Post date:** [November 6, 2023, 5:47pm UTC](https://forum.finsweet.com/t/redirect-to-different-page-and-retain-selection/2139/5 "2023-11-06T17:47:21Z")

</div>

Sorry, I had not opened your homepage yet. I see you have the dropdowns already on the live site so it’s all good.

By adding the missing JS, I meant that I can jump to your live site and write the missing code for your solution as at the moment we only have the search bar working. I will then share this code for you to add it to your custom code section inside Webflow.

---

<div class="post-metadata">

**Author:** ![Marc](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/marc/32/1583_2.png) [@Marc](https://forum.finsweet.com/u/Marc)\
**Post date:** [November 6, 2023, 5:53pm UTC](https://forum.finsweet.com/t/redirect-to-different-page-and-retain-selection/2139/6 "2023-11-06T17:53:11Z")

</div>

Ok, awesome. Thanks, Luis. Do you need a read-only or something?

---

<div class="post-metadata">

**Author:** ![Support-Luis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/support-luis/32/53_2.png) [@Support-Luis](https://forum.finsweet.com/u/Support-Luis)\
**Post date:** [November 6, 2023, 6:40pm UTC](https://forum.finsweet.com/t/redirect-to-different-page-and-retain-selection/2139/7 "2023-11-06T18:40:12Z")

</div>

No need! 💪

---

<div class="post-metadata">

**Author:** ![Support-Luis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/support-luis/32/53_2.png) [@Support-Luis](https://forum.finsweet.com/u/Support-Luis)\
**Post date:** [November 6, 2023, 8:14pm UTC](https://forum.finsweet.com/t/redirect-to-different-page-and-retain-selection/2139/8 "2023-11-06T20:14:40Z")

</div>

Hey @marc! I will need you to modify one thing before I can send the complete code, can you change the group name for the Lincese checkboxes?

Right now both checkbox groups have the same `name="Checkbox-10"` and this is creating some conflict on the code. You can name them `name="Checkbox-11"`. Also please add a unique id to your text input 🙏

---

<div class="post-metadata">

**Author:** ![Marc](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/marc/32/1583_2.png) [@Marc](https://forum.finsweet.com/u/Marc)\
**Post date:** [November 7, 2023, 10:21am UTC](https://forum.finsweet.com/t/redirect-to-different-page-and-retain-selection/2139/9 "2023-11-07T10:21:00Z")

</div>

Hi Luis, I believe I configured everything according to your requirements and as far as I understand things.

I am a bit unsure about the unique id for the text input, because there was an ID already and I believe it was unique (at least on the homepage). You do mean the search field, with the class of `fs_cmsfilter_search-field`, right?

In any way: many thanks for your support for this custom adjustment. 🙏

Looking forward to you checking if everything is correct now and to the code, naturally. 🤗

---

<div class="post-metadata">

**Author:** ![Support-Luis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/support-luis/32/53_2.png) [@Support-Luis](https://forum.finsweet.com/u/Support-Luis)\
**Post date:** [November 7, 2023, 12:04pm UTC](https://forum.finsweet.com/t/redirect-to-different-page-and-retain-selection/2139/10 "2023-11-07T12:04:11Z")

</div>

Hey @Marc! Thanks for the adjustments! There is only one more thing I forgot to mention, can you add the id `submit-button` to the search button?

I believe this is the last adjustment for the code to work, you can copy/paste this into the `</body>` section for custom code on your homepage.

```js
<script>
      window.onload = () => {
        const button = document.getElementById('submit-button');

        function gatherUserInput() {
          const userInput = document.getElementById('Search').value;

          const selectedSubjects = Array.from(
            document.querySelectorAll('input[name="Checkbox-Subject"]:checked')
          ).map((input) => input.nextElementSibling.textContent);

          const selectedLicenseTypes = Array.from(
            document.querySelectorAll('input[name="Checkbox-Licence"]:checked')
          ).map((input) => input.nextElementSibling.textContent);

          const queryParams = {};

          if (userInput.trim() !== '') {
            queryParams['*'] = userInput.replaceAll(' ', '+');
          }

          if (selectedSubjects.length > 0) {
            queryParams['subject'] = selectedSubjects.join('%2');
          }

          if (selectedLicenseTypes.length > 0) {
            queryParams['licence-type'] = selectedLicenseTypes.join('%2');
          }

          let queryString;
          queryString = Object.keys(queryParams)
            .map((key) => `${key}=${queryParams[key]}`)
            .join('&');

          const gatheredData = `/image-suppliers?${queryString}`;

          return gatheredData;
        }

        button.addEventListener('click', function (e) {
          e.preventDefault();
          const url = gatherUserInput();
          window.location.href = url;
        });
      };
    </script>

```

Let me know how it goes!

---

<div class="post-metadata">

**Author:** ![Marc](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/marc/32/1583_2.png) [@Marc](https://forum.finsweet.com/u/Marc)\
**Post date:** [November 7, 2023, 1:26pm UTC](https://forum.finsweet.com/t/redirect-to-different-page-and-retain-selection/2139/11 "2023-11-07T13:26:53Z")

</div>

It’s all working perfectly! Thanks again. 😍

---

<div class="post-metadata">

**Author:** ![Support-Luis](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.finsweet.com/support-luis/32/53_2.png) [@Support-Luis](https://forum.finsweet.com/u/Support-Luis)\
**Post date:** [November 7, 2023, 2:05pm UTC](https://forum.finsweet.com/t/redirect-to-different-page-and-retain-selection/2139/12 "2023-11-07T14:05:58Z")

</div>

You are welcome! 💪
