TDG
TDG

Reputation: 1302

Selectize - on change add URL parameter and refresh the page

URL using "http://localhost:8000/test.html"

I want to change URL to "http://localhost:8000/test.html?countrycode=SG" or "http://localhost:8000/test.html?countrycode=MY" or "http://localhost:8000/test.html?countrycode=IN" based on the selectize value selected.

Also, On select change it have get value and refresh the page.

Thanks

HTML:

<div class="select-container">
  <select class="custom-select">
    <option value="SG">Singapore</option>
    <option value="MY">Malaysia</option>
    <option value="IN">India</option>
  </select>
</div>

JS:

$('.custom-select').selectize();

Upvotes: 0

Views: 1380

Answers (2)

TDG
TDG

Reputation: 1302

solution found for this question:

var urlpath = window.location.origin + window.location.pathname; window.location = urlpath+'?countrycode=' + value;

Thanks

Upvotes: 1

Jalay Oza
Jalay Oza

Reputation: 762

You can do this

<div class="select-container">
  <select class="custom-select">
    <option value="SG">Singapore</option>
    <option value="MY">Malaysia</option>
    <option value="IN">India</option>
  </select>
</div>

$(function() {
  $('.custom-select').selectize({
      onChange: function(value) {
        window.location = $getURLPath+'?countrycode=' + value;
      }
  });
});

Demo : http://jsfiddle.net/jalayoza/uZmcD/88/

Hope this helps

Upvotes: 0

Related Questions