Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Document</title>
- <script>
- function getAjax(url, success) {
- var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');
- xhr.onreadystatechange = function () {
- if (xhr.readyState > 3 && xhr.status === 200) {
- success(xhr.responseText);
- }
- };
- xhr.open('GET', url);
- xhr.send();
- return xhr;
- }
- function getSoapRequest() {
- var url = 'http://www.jozefkapusta.teacher.sk/xml/HelloClientWsdl.php?operation=currency';
- getAjax(url, function (data) {
- currenciesJson = JSON.parse(data)
- console.log(currenciesJson);
- rates = currenciesJson.rates;
- selectList = document.getElementById('to');
- selectListFrom = document.getElementById('from');
- option = document.createElement("option");
- option.value = 1;
- option.text = currenciesJson.base;
- selectListFrom.appendChild(option);
- for (let index in rates) {
- option = document.createElement("option");
- option.value = rates[index];
- option.text = index;
- selectList.appendChild(option);
- }
- });
- }
- function calculate() {
- selectList = document.getElementById('to');
- userValue = parseInt(document.getElementById('number').value);
- var value = selectList.options[selectList.selectedIndex].value;
- document.getElementById('result').innerHTML = value*userValue;
- }
- getSoapRequest();
- </script>
- </head>
- <body>
- <h1>Currencies calculator</h1>
- <div id="demo">
- <select name="from" id="from" disabled></select>
- <select name="to" id="to"></select>
- <input type="number" name="number" id="number">
- <button onclick="calculate()">Calculate</button>
- </div>
- <h1>Result</h1>
- <p id="result"></p>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement