SHARE
TWEET

Untitled

a guest Mar 24th, 2019 59 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var defaultUsd = null;
  2.  
  3. xhr.onreadystatechange = function (res) {
  4.     if( xhr.readyState == 4) {
  5.        
  6.         var responseObject = JSON.parse(xhr.responseText);
  7.         defaultUsd = responseObject[0].buy;
  8.        
  9.         console.log(responseObject[3].sale);
  10.         console.log(responseObject);
  11.         showCurrency(responseObject);          
  12.     }
  13. };
  14.  
  15. xhr.send();
  16.  
  17. function showCurrency (currency) {
  18.    
  19.     var currencyFrom = document.getElementById('from');
  20.     var currencyTo = document.getElementById('to');
  21.    
  22.     for ( var c in currency) {
  23.        
  24.         // одним циклом рисуем 2 опции со значениями для двух селектов
  25.         var currencyOption = document.createElement('option');
  26.         var currencyOption2 = document.createElement('option');
  27.        
  28.         var currencyText = document.createTextNode(currency[c].ccy);
  29.         var currencyText2 = document.createTextNode(currency[c].ccy);
  30.        
  31.         currencyOption.appendChild(currencyText);
  32.         currencyOption2.appendChild(currencyText2);
  33.        
  34.         currencyOption.dataset.buy = currency[c].buy;
  35.         currencyOption2.dataset.buy = currency[c].buy;
  36.        
  37.         currencyFrom.appendChild(currencyOption);
  38.         currencyTo.appendChild(currencyOption2);
  39.        
  40.     }
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top