c4udok,
document.addEventListener("DOMContentLoaded", function() {
let db = [{
ISO4217: '$',
multiply: 1
},
{
ISO4217: 'RUB',
multiply: 70.5
},
{
ISO4217: 'UAH',
multiply: 27
}
];
document.addEventListener('change', function({target}) {
if(target.closest('#valuta, [name="nameRadio"]')) {
let option = db[document.querySelector('#valuta').selectedIndex];
rebuildPrices(option);
}
});
function rebuildPrices({ISO4217, multiply}) {
const val = document.querySelector('[name="nameRadio"]:checked').value || 1;
document.querySelector('#rezultatRadio').innerHTML = val;
[...document.querySelectorAll('[data-cost]')].forEach(el => {
const num = el.dataset.cost,
span = el.querySelector('span');
span.innerHTML = `${(num * multiply * val).toFixed(2)} ${ISO4217}`;
})
}
rebuildPrices(db[0])
});