I am building a website that has English and Macedonian but the problem is, when I click in "MK" it changes to the Macedonian version of my website but the selector stays on EN and if I wanted to switch back to English I couldn’t the selector becomes useless. What is the problem that I can’t find? Here is the code for html and js.
`<header>
<nav>
<center>
<ul class="nav-links">
<li><a href="/">Home</a></li>
<li><a href="contact.html">Contact</a></li>
<li><a href="about.html">About</a></li>
<li>
<select id="language-selector">
<option value="en">EN</option>
<option value="mk">MK</option>
</select>
</li>
</ul>
</center>
</nav>
</header>
<script>
const langSelector = document.querySelector('#language-selector');
langSelector.addEventListener('change', function() {
let lang = this.value;
let url = window.location.href;
let newUrl;
if (lang === 'mk') {
newUrl = url.replace(/(index.html)$/, 'mk/home-mk.html');
} else {
newUrl = url.replace(/(mk\/home-mk.html)$/, 'index.html');
}
window.location.href = newUrl;
});
</script>`
I tried everything that came to my mind I even changed the whole js but I can’t seem to figure it out.
>Solution :
Add the selected attribute for the MK option on the mk/home-mk.html page.
<select id="language-selector">
<option value="en">EN</option>
<option value="mk" selected>MK</option>
</select>