Changing the text in the dropdown trigger with the selected option


On my site I want to have a language selection dropdown (EN English, NL Dutch, FR French). It looks like this:


All the animations etc are OK, but I’d like the text in the dropdown trigger to reflect the current selection… So if someone selects “FR” for French, the trigger should change to FR. Is there an option I overlooked or do I need to do it via Javascript?

Thanks & cheers --Mike

Here is my site Read-Only: LINK
(how to share your site Read-Only link)

I guess the drop down is part of the navbar symbol - so you should use custom code.

In general this ± the code outline.

If this is your dropdown values:

<div class="dropdown">
    <option value="en">en</option>
    <option value="fr">fr</option>
  /* copy-paste before body inside fr pages */
  $(".dropdown select").val("fr");

Extra reading:


More modular/DRY is to create ifrelated to url slug (If url contain fr select fr).

if (window.location.href.indexOf("/fr/") > -1) {
  //  block of code to be executed if condition1 is true
   $(".dropdown select").val("fr");
} else if (window.location.href.indexOf("/en/") > -1) {
  //  block of code to be executed if the condition1 is false and condition2 is true
   $(".dropdown select").val("en");

But “no way” to give you a specific answer without read-only link.

Thanks @Siton_Systems, that will do nicely. I thought that indeed JS was needed for the job. Your solution is very elegant however, I was going to fiddle with the dropdown itself :slight_smile:

Sorry I didn’t share the site as it should, I just realised I should have done that differently. But I’m OK now.

Thanks again & cheers --Mike