Почему когда я вставляю второй код js то получается каша. Кто знает как сделайте, пожалуйста, что бы селект меню открывалось как на картинке
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Currency Converter</title>
<link rel="stylesheet" href="Untitled-1.css">
<script src="main.js" defer></script>
</head>
<body>
<div class="charity__currencies">
<a class="exchange__rates">Курси валют</a>
<div class="custom-select" style="width:140px;">
<select id="currencySelect">
<option value="0">У відділенях</option>
<option value="1">У відділенях</option>
<option value="2">Для карток</option>
<option value="3">НБУ</option>
</select>
</div>
</div>
<div class="rates">
<a class="eur">EUR</a>
<a class="uan__buy">UAN</a>
<a class="usd">USD</a>
<a class="uan1__buy">UAN</a>
<a class="pln">PLN</a>
<a class="uan2__buy">UAN</a>
<a class="purchase">Купівля</a>
<a id="eur__buy-price" class="eur__buy-price">39.85</a>
<a id="eur__sell-price" class="eur__sell-price">40.85</a>
<a id="usd__buy-price" class="usd__buy-price">37.1</a>
<a id="usd__sell-price" class="usd__sell-price">37.6</a>
<a id="pln__buy-price" class="pln__buy-price">8.77</a>
<a id="pln__sell-price" class="pln__sell-price">9.35</a>
<a class="sell">Продаж</a>
</div>
</body>
</html>
body{
background-color: #D9D9D9;
}
#currencySelect{
border: none;
margin-left: 2vw;
margin-top: 0.6vh;
}
.exchange__rates{
padding: 25px;
}
.charity__currencies{
position: absolute;
background-color: #fff;
border-radius: 35px;
width: 30vw;
height: 30vh;
}
.sell{
color: #000;
font-size: 15px;
font-family: 'Rubik', sans-serif;
font-weight: 300;
position: absolute;
margin-top: 8vh;
margin-left: 11vw;
}
.purchase{
color: #000;
font-size: 15px;
font-family: 'Rubik', sans-serif;
font-weight: 300;
position: absolute;
margin-top: 8vh;
margin-left: 4vw;
}
.eur{
color: #000;
font-size: 25px;
font-family: 'Rubik', sans-serif;
font-weight: 400;
position: absolute;
margin-top: 12vh;
margin-left: -11vw;
}
.uan__buy{
color: #DFE1E1;
font-size: 25px;
font-family: 'Rubik', sans-serif;
font-weight: 400;
position: absolute;
margin-top: 12vh;
margin-left: -7vw;
}
.usd{
color: #000;
font-size: 25px;
font-family: 'Rubik', sans-serif;
font-weight: 400;
position: absolute;
margin-top: 19vh;
margin-left: -11vw;
}
.uan1__buy{
color: #DFE1E1;
font-size: 25px;
font-family: 'Rubik', sans-serif;
font-weight: 400;
position: absolute;
margin-top: 19vh;
margin-left: -7vw;
}
.pln{
color: #000;
font-size: 25px;
font-family: 'Rubik', sans-serif;
font-weight: 400;
position: absolute;
margin-top: 26vh;
margin-left: -11vw;
}
.uan2__buy{
color: #DFE1E1;
font-size: 25px;
font-family: 'Rubik', sans-serif;
font-weight: 400;
position: absolute;
margin-top: 26vh;
margin-left: -7vw;
}
.eur__buy-price{
color: #000;
font-size: 23px;
font-family: 'Rubik', sans-serif;
font-weight: 300;
position: absolute;
margin-top: 12vh;
margin-left: 4vw;
}
.eur__sell-price{
color: #000;
font-size: 23px;
font-family: 'Rubik', sans-serif;
font-weight: 300;
position: absolute;
margin-top: 12vh;
margin-left: 11vw;
}
.usd__buy-price{
color: #000;
font-size: 23px;
font-family: 'Rubik', sans-serif;
font-weight: 300;
position: absolute;
margin-top: 19vh;
margin-left: 4vw;
}
.usd__sell-price{
color: #000;
font-size: 23px;
font-family: 'Rubik', sans-serif;
font-weight: 300;
position: absolute;
margin-top: 19vh;
margin-left: 11vw;
}
.pln__buy-price{
color: #000;
font-size: 23px;
font-family: 'Rubik', sans-serif;
font-weight: 300;
position: absolute;
margin-top: 26vh;
margin-left: 4vw;
}
.pln__sell-price{
color: #000;
font-size: 23px;
font-family: 'Rubik', sans-serif;
font-weight: 300;
position: absolute;
margin-top: 26vh;
margin-left: 11vw;
}
.rates{
position: absolute;
display: flex;
margin-left: 11vw;
margin-top: -4.5vh;
padding: 5px 25px;
}
.custom-select {
display: flex;
justify-content: center;
align-items: center;
margin: 0 auto;
width: 200px;
}
.select-selected:after {
position: absolute;
content: "";
top: 14px;
right: 10px;
width: 0;
height: 0;
border: 6px solid transparent;
border-color: #93989d transparent transparent transparent;
}
.select {
position: absolute;
width: 7.5vw;
margin-bottom: 30px;
box-sizing: border-box;
border: none;
margin-top: 10.3vh;
margin-left: -20vw;
}
.option {
background: none;
border: none;
color: #000000;
font-size: 15px;
cursor: pointer;
}
.custom-select {
position: relative;
font-family: 'Rubik', sans-serif;
font-weight: 300;
font-size: 15px;
margin-left: -1vw;
margin-top: 1vh;
}
.select-selected:after {
position: absolute;
content: "";
top: 14px;
right: 10px;
width: 0;
height: 0;
border: 6px solid transparent;
border-color: #93989d transparent transparent transparent;
}
/* .select-selected.select-arrow-active:after {
border-color: transparent transparent #93989d transparent;
top: 7px;
} */
.select-items div,.select-selected {
color: #000;
padding: 8px 16px;
border-color: transparent transparent rgba(0, 0, 0, 0.1) transparent;
cursor: pointer;
}
.select-items {
position: absolute;
background-color: #fff;
top: 100%;
margin: 3px;
left: 0;
right: 0;
z-index: 1;
box-shadow: 0 0 10px 0 rgba(0,0,0,.23);
}
.custom-select select {
font-size: 15px;
}
.custom-select select option {
text-decoration: none;
}
.select-items div:hover, .same-as-selected {
color: #7ED957 !important;
transition: 0.3s;
}
#eur__credit{
display: none;
}
// Add an event listener to the select element
document.getElementById('currencySelect').addEventListener('change', function() {
// Get the selected option value
var selectedOption = this.value;
// Update currency values based on the selected option
if (selectedOption === '2') { // Для карток
document.getElementById('eur__buy-price').textContent = '38.939';
document.getElementById('eur__sell-price').textContent = '40.816';
document.getElementById('usd__buy-price').textContent = '36.264';
document.getElementById('usd__sell-price').textContent = '37.453';
document.getElementById('pln__buy-price').textContent = '8.95';
document.getElementById('pln__sell-price').textContent = '9.267';
// Update other currency values accordingly
} else {
// Reset the values to their default if another option is selected
document.getElementById('eur__buy-price').textContent = '39.85';
document.getElementById('eur__sell-price').textContent = '40.85';
document.getElementById('usd__buy-price').textContent = '37.1';
document.getElementById('usd__sell-price').textContent = '37.6';
document.getElementById('pln__buy-price').textContent = '8.77';
document.getElementById('pln__sell-price').textContent = '9.35';
// Reset other currency values accordingly
if (selectedOption === '3') { // Для карток
document.getElementById('eur__buy-price').textContent = '39.39';
document.getElementById('eur__sell-price').textContent = '39.39';
document.getElementById('usd__buy-price').textContent = '36.26';
document.getElementById('usd__sell-price').textContent = '36.26';
document.getElementById('pln__buy-price').textContent = '8.96';
document.getElementById('pln__sell-price').textContent = '8.96';
// Update other currency values accordingly
} else {
// Reset the values to their default if another option is selected
document.getElementById('eur__buy-price').textContent = '39.85';
document.getElementById('eur__sell-price').textContent = '40.85';
document.getElementById('usd__buy-price').textContent = '37.1';
document.getElementById('usd__sell-price').textContent = '37.6';
document.getElementById('pln__buy-price').textContent = '8.77';
document.getElementById('pln__sell-price').textContent = '9.35';
// Reset other currency values accordingly
}
}
});
Вот код при котором все как на картинке, но при выборе пункта селект меню ничего не меняется
let x, i, j, l, ll, selElmnt, a, b, c;
x = document.getElementsByClassName("custom-select");
l = x.length;
for (i = 0; i < l; i++) {
selElmnt = x[i].getElementsByTagName("select")[0];
ll = selElmnt.length;
a = document.createElement("DIV");
a.setAttribute("class", "select-selected");
a.innerHTML = selElmnt.options[selElmnt.selectedIndex].innerHTML;
x[i].appendChild(a);
b = document.createElement("DIV");
b.setAttribute("class", "select-items select-hide");
for (j = 1; j < ll; j++) {
c = document.createElement("DIV");
c.innerHTML = selElmnt.options[j].innerHTML;
c.addEventListener("click", function(e) {
let y, i, k, s, h, sl, yl;
s = this.parentNode.parentNode.getElementsByTagName("select")[0];
sl = s.length;
h = this.parentNode.previousSibling;
for (i = 0; i < sl; i++) {
if (s.options[i].innerHTML == this.innerHTML) {
s.selectedIndex = i;
h.innerHTML = this.innerHTML;
y = this.parentNode.getElementsByClassName("same-as-selected");
yl = y.length;
for (k = 0; k < yl; k++) {
y[k].removeAttribute("class");
}
this.setAttribute("class", "same-as-selected");
break;
}
}
h.click();
});
b.appendChild(c);
}
x[i].appendChild(b);
a.addEventListener("click", function(e) {
e.stopPropagation();
closeAllSelect(this);
this.nextSibling.classList.toggle("select-hide");
this.classList.toggle("select-arrow-active");
});
}
function closeAllSelect(elmnt) {
let x, y, i, xl, yl, arrNo = [];
x = document.getElementsByClassName("select-items");
y = document.getElementsByClassName("select-selected");
xl = x.length;
yl = y.length;
for (i = 0; i < yl; i++) {
if (elmnt == y[i]) {
arrNo.push(i)
} else {
y[i].classList.remove("select-arrow-active");
}
}
for (i = 0; i < xl; i++) {
if (arrNo.indexOf(i)) {
x[i].classList.add("select-hide");
}
}
}
document.addEventListener("click", closeAllSelect);
const currencyTypeSelect = document.querySelector("#currency-type");
введите сюда код
