0

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();
2
  • I have given example with live demo as well, please let me know if this not helps Commented Jun 6, 2017 at 5:49
  • Hey Can you please vote my answer if it helps you, Thanks Commented Jun 6, 2017 at 6:05

2 Answers 2

1

solution found for this question:

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

Thanks

Sign up to request clarification or add additional context in comments.

Comments

0

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

9 Comments

Hi.. Thanks for your valuable hints. but, on each change, it adds to the url like test.html?countrycode=uk?countrycode=us?countrycode=us?countrycode=in
Sorry.. i use like this var $getURLPath = window.location.href; window.location = $getURLPath+'?countrycode=' + value;
Hi Yes on each change it will redirect to localhost:8000/test.html?countrycode=MY or SG or whatever contrycode you mention in value of select, I have created demo for you as per my understanding
Everything works as requrired. But on each change, previous parameter is not removing. new change value getting added to the existing parameter like this "test.html?countrycode=uk?countrycode=us"
what you are getting in $getURLPath? you just need $getURLPath = 'http://'+ window.location.hostname+'test.html?countrycode='+ value
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.