How to get the selected value after redirect in given website

Look at the website:

The drop down section left to twitter and linkedin symbols. In this, when i choose any option, it goes to that given url but default value of select box does not change. How to change the value according to that.

For example, I choose United States, it redirects to the but values of the select box remains australia. How to correct it. Does it need any jquery code? Please explain in detail.



Just use the selected attribute to select the option that should be displayed on page load.


 <option value="">Australia</option>
 <option value="" [B][COLOR="#FF0000"]selected[/COLOR][/B]>United states</option>
 <option value="">Singapore</option>
 <option value="">India</option>

Have you checked my site
In that, at the top left to twitter symbol. I have tried it. But not working. Many people said it will not work after page load.

Do you know any other solution?


What did you try?
How is it not working?

It would help if you could be a little more specific :slight_smile:

okay. i have used only a onchange event handler like this when a option is selected.

<select onchange="test(this.options[this.selectedIndex].value)" style="width:120px">

and a small js function which is mostly worthless.

<script type="text/javascript">
function test(url) {
window.location = url.toString();


And I have a another helping site

In that site, check the currency changer in top right. I want the same functionality like this currency changer.

On your original site, when you select an option from the dropdown menu, your JS code is redirecting you to a new url (using window.location).
Doesn’t this mean that you are loading a new page?

Yes, I know i am loading new page. If there any solution for this?
If you know the solution with the ajax page load. Please share.

On your new page then, do this:

 <option value="">Australia</option>
 <option value="" [B][COLOR="#FF0000"]selected[/COLOR][/B]>United states</option>
 <option value="">Singapore</option>
 <option value="">India</option>

Whereby you add the selected attribute to whichever option should be pre-selected.
Unless I’m missing something, it is that simple :slight_smile:

I could do that but problem is this is in a single file “header.php”. I think this can be achieved with jquery ajax. I am weak in js. So, if you know jquery ajax, You can create a code.
Thanks for the replies.

Ah, ok, now I understand.

Sure you can do this with JavaScript.
I’ll use jQuery, because you are including it on the page anyway, but it’s not really necessary.
For this to work, you need to give the select element a unique id (e.g. “mySelect”) and the values of the option elements must be the same format as the url

  $("#mySelect > option").each(function() {
    if(this.value == window.location.pathname){
      this.selected = 'selected';