I am trying to navigate to a page on language selection. Here is my HTML code which I got from a template.
<div class="change-language">
<select class="select-language selectpicker">
<option value="en">Türkçe</option>
<option value="ge">English</option>
</select>
</div>
How can I navigate to a page when a user selects a language? I have to do it with JQuery.
I am trying to navigate to a page on language selection. Here is my HTML code which I got from a template.
<div class="change-language">
<select class="select-language selectpicker">
<option value="en">Türkçe</option>
<option value="ge">English</option>
</select>
</div>
How can I navigate to a page when a user selects a language? I have to do it with JQuery.
Share Improve this question edited Sep 23, 2014 at 19:11 Devin 7,7306 gold badges43 silver badges56 bronze badges asked Sep 23, 2014 at 19:08 Arif YILMAZArif YILMAZ 5,88629 gold badges114 silver badges197 bronze badges5 Answers
Reset to default 2Well... here's a really simple example simply redirecting to page on an onchange event.
The page that it redirects to is simply the value of the dropdown and the file extension of the target file.
$('.select-language').on('change',function(){
var value = $(this).val();
location.href = value +'.html'; //or .php, etc. This will go to a page called en.html
});
More specifik target involving the protocol:
$('.select-language').on('change',function(){
var value = $(this).val();
location.href = 'http://your-url./'+ value +'.html'; //or .php, etc. This will go to a page called en.html
});
You can do smth like the following:
HTML:
<div class="change-language">
<select class="select-language selectpicker">
<option value="page-tu.html">Türkçe</option>
<option value="page-en.html">English</option>
</select>
</div>
And JQuery:
$('.select-language').on('change', function(){
location.href = $(this).val();
});
Below code will help you
jquery:
$(document).ready(function(){
$(".select-language").change(function(){
var page_url = "http://"+$(".select-language").val()+".";
$(location).attr('href',page_url);
});
});
If you want to redirect to www.mypage./en
$(".select-language.selectpicker").on("change", function(){
window.location.href = this.value;
});
$(".select-language").on("change", function() {
//Will redirect to en.url., ge.url., etc...
window.location.href = "http://" + this.value + ".url.";
});