# Redirecting a user to a page using a custom drop-down bar

**URL:** <https://forum.wixstudio.com/t/redirecting-a-user-to-a-page-using-a-custom-drop-down-bar/41768>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [May 23, 2018, 9:04am UTC](https://forum.wixstudio.com/t/redirecting-a-user-to-a-page-using-a-custom-drop-down-bar/41768 "2018-05-23T09:04:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![liorc](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/liorc/32/1121_2.png) [@liorc](https://forum.wixstudio.com/u/liorc)\
**Post date:** [May 23, 2018, 9:04am UTC](https://forum.wixstudio.com/t/redirecting-a-user-to-a-page-using-a-custom-drop-down-bar/41768/1 "2018-05-23T09:04:08Z")

</div>

Hi friends.  
I created a custom drop-down language bar and I want that whenever a user will choose a language from that drop-down the page automatically will be redirected to the home page of that certain language. Here are two screenshots for your convenience.

Screenshot 1:

 ![](https://us1.discourse-cdn.com/wix/original/3X/0/7/077851e88ab8a69b52b76326549358228a8f0ad6.jpeg)

Screenshot 2:

 ![](https://us1.discourse-cdn.com/wix/original/3X/d/3/d37d02d7f20677245d7347eaad822f17e423f000.jpeg)

Here is the basic idea of the process:

1. As default, the user will enter the english homepage ([mysite.com/en](http://mysite.com/en)).
2. When a user will click on a different language using the drop-down bar I made, such as German, the page will be transferred automatically to the German homepage ([mysite.com/ger](http://mysite.com/ger)).

Any suggestion on how to make this happen?

Best,

Lior

---

<div class="post-metadata">

**Author:** ![chris-derrell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/chris-derrell/32/1774_2.png) [@chris-derrell](https://forum.wixstudio.com/u/chris-derrell)\
**Post date:** [May 23, 2018, 11:37am UTC](https://forum.wixstudio.com/t/redirecting-a-user-to-a-page-using-a-custom-drop-down-bar/41768/2 "2018-05-23T11:37:38Z")

</div>

Hey Lior,

What you want to use is the **onChange** method of the dropdown. To setup, you will first need to set the value of each of the dropdown’s options to your language codes (en,ger,heb). Then you can do this like so:

```javascript
 import wixLocation from 'wix-location'
 
 $w("#languageSelector").onChange( (event, $w) => { 
     let lang = event.target.value; // or use $w("#languageSelector").value
     langPath = wixLocation.path[0];//The current language setting of that webpage
     switch(lang){
         case "en":
             if(langPath!= "en") wixLocation.to('/en'); 
             //Will only run if the current page is not already set to english.
             break;
         case "heb": 
             if(langPath!= "heb") wixLocation.to('/heb');
             break; 
         case "ger": 
             if(langPath!= "ger") wixLocation.to('/ger'); 
             break;
         default:
             wixLocation.to('/en');
     }
 
 
 }); 

```

For references, you can check the dropdown and wix-location documentation.

---

<div class="post-metadata">

**Author:** ![liorc](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/liorc/32/1121_2.png) [@liorc](https://forum.wixstudio.com/u/liorc)\
**Post date:** [May 23, 2018, 11:43am UTC](https://forum.wixstudio.com/t/redirecting-a-user-to-a-page-using-a-custom-drop-down-bar/41768/3 "2018-05-23T11:43:26Z")

</div>

I’ll give it a try, thanks a lot!

---

<div class="post-metadata">

**Author:** ![liorc](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/liorc/32/1121_2.png) [@liorc](https://forum.wixstudio.com/u/liorc)\
**Post date:** [May 23, 2018, 12:25pm UTC](https://forum.wixstudio.com/t/redirecting-a-user-to-a-page-using-a-custom-drop-down-bar/41768/4 "2018-05-23T12:25:49Z")

</div>

Chris, I tried and it is not working (see the screenshot at the bottom).  
I set the value of each of the drop-down’s options as you mentioned, changed to the default drop-down’s name in the code and created 3 pages with the same address endings for redirection purposes (en, heb, ger). Still, it doesn’t work. What’s your take on this?

 ![](https://us1.discourse-cdn.com/wix/original/3X/c/1/c1c21b6031bed99e18fd146287849ceee6618033.jpeg)

---

<div class="post-metadata">

**Author:** ![chris-derrell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/chris-derrell/32/1774_2.png) [@chris-derrell](https://forum.wixstudio.com/u/chris-derrell)\
**Post date:** [May 23, 2018, 5:25pm UTC](https://forum.wixstudio.com/t/redirecting-a-user-to-a-page-using-a-custom-drop-down-bar/41768/5 "2018-05-23T17:25:53Z")

</div>

Can you send a link to your website?

---

<div class="post-metadata">

**Author:** ![chris-derrell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/chris-derrell/32/1774_2.png) [@chris-derrell](https://forum.wixstudio.com/u/chris-derrell)\
**Post date:** [May 23, 2018, 5:29pm UTC](https://forum.wixstudio.com/t/redirecting-a-user-to-a-page-using-a-custom-drop-down-bar/41768/6 "2018-05-23T17:29:45Z")

</div>

Oh! You have to put all of the onChange code within the $w.onReady() function that wix provides. So it should look like this.

```javascript
import wixLocation from 'wix-location';
$w.onReady(function () {
	//Paste all your code in here.
	$w("#dropdown1).onChange( (event,$w)=>{
	   ...
	});
});

```

Make sure that you change the case “heb” to case “hebrew”.

---

<div class="post-metadata">

**Author:** ![chris-derrell](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/chris-derrell/32/1774_2.png) [@chris-derrell](https://forum.wixstudio.com/u/chris-derrell)\
**Post date:** [May 23, 2018, 5:39pm UTC](https://forum.wixstudio.com/t/redirecting-a-user-to-a-page-using-a-custom-drop-down-bar/41768/7 "2018-05-23T17:39:11Z")

</div>

Last one 🙂

I’ve done a working version here - [https://derrellchristopher.wixsite.com/mysite/test2](https://derrellchristopher.wixsite.com/mysite/test2)

The complete code I used is here.

```javascript
// For full API documentation, including code examples, visit http://wix.to/94BuAAs

import wixLocation from 'wix-location';

$w.onReady(function () {
	//TODO: write your page related code here...
	$w("#dropdown1").onChange( (event, $w) => { 
     let lang = event.target.value; // or use $w("#languageSelector").value
     let langPath = wixLocation.path[0];//The current language setting of that webpage
     console.log(langPath);
     switch(lang){
         case "en":
             if(langPath!= "en") wixLocation.to('/en'); 
             //Will only run if the current page is not already set to english.
             break;
         case "heb": 
             if(langPath!= "heb") wixLocation.to('/heb');
             break; 
         case "ger": 
             if(langPath!= "ger") wixLocation.to('/ger'); 
             break;
         default:
             wixLocation.to('/en');
     }
 
 }); 
});

```

---

<div class="post-metadata">

**Author:** ![liorc](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/liorc/32/1121_2.png) [@liorc](https://forum.wixstudio.com/u/liorc)\
**Post date:** [May 23, 2018, 5:42pm UTC](https://forum.wixstudio.com/t/redirecting-a-user-to-a-page-using-a-custom-drop-down-bar/41768/8 "2018-05-23T17:42:13Z")

</div>

Chris - you are THE MAN!  
Thanks a lot bro, you helped a lot.

Best,

Lior

---

<div class="post-metadata">

**Author:** ![jasper-eric](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/jasper-eric/32/33385_2.png) [@jasper-eric](https://forum.wixstudio.com/u/jasper-eric)\
**Post date:** [May 15, 2022, 4:20am UTC](https://forum.wixstudio.com/t/redirecting-a-user-to-a-page-using-a-custom-drop-down-bar/41768/9 "2022-05-15T04:20:51Z")

</div>

Chris from 4 years ago, thank you! They really should fix this in the platform, but your solution worked!
