Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix JavaScript function that prevents dropdown list from working

My complete JavaScript code is https://jsfiddle.net/JSstarter/0t98gbg3/. Dropdown list worked, but after I add setFormat function, the dropdown list stops working and it doesn't show the list of locales. Can someone please help me how to fix the JavaScript part to get the dropdown list and also the setFormat function to work?

<p id="demo">Please select a locale to show data.</p>
<div class="dropdown">
<button onclick="myFunction()" class="dropbtn">Locales</button>
<div id="locale" class="dropdown-content">
<a href="#enUS" onclick="setFormat('en-US')">en-US</a>
<a href="#koKR" onclick="setFormat('ko-KR')">ko-KR</a>
<a href="#zhCN" onclick="setFormat('zh-Hans-CN')">zh-Hans-CN</a>
<a href="#jaJP" onclick="setFormat('ja-JP')">ja-JP</a>
<a href="#deDE" onclick="setFormat('de-DE')">de-DE</a>
<a href="#ruRU" onclick="setFormat('ru-RU')">ru-RU</a>
<a href="#arSA" onclick="setFormat('ar-SA')">ar-SA</a>
</div>
</div>
<script>

function myFunction() {
document.getElementById("locale").classList.toggle("show");
}

setFormat(locale) {
var date = new Date(2016, 1, 14, 0, 0, 0);
document.getElementByID("demo").innerHTML = new Intl.DateTimeFormat('en-   US').format(date);
document.getElementByID("demo").innerHTML = new Intl.NumberFormat('en-US').format(1234.56);
};

</script>
like image 427
user5772458 Avatar asked Jun 14 '26 02:06

user5772458


1 Answers

Super easy fix. You are missing the word 'function' before setFormat(locale). Also I noticed you are passing the variable 'locale' but you don't actually use it in the function. I assume you might need that later on but just pointing it out.

<script>

function setFormat(locale) {
    var date = new Date(2016, 1, 14, 0, 0, 0);
    document.getElementByID("demo").innerHTML = new Intl.DateTimeFormat('en-US').format(date);
    document.getElementByID("demo").innerHTML = new Intl.NumberFormat('en-US').format(1234.56);
};

function myFunction() {
    document.getElementById("locale").classList.toggle("show");
}


</script>
like image 187
JPA9000 Avatar answered Jun 15 '26 17:06

JPA9000