-
Notifications
You must be signed in to change notification settings - Fork 6
/
currency.html
33 lines (31 loc) · 925 Bytes
/
currency.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE html>
<html>
<head>
<title>URL encoded</title>
</head>
<body>
<label for="in" id="for_in">from</label>
<input id="in" name="in">
<label for="out" id="for_out">to</label>
<input id="out" name="out">
<input id="convert" type="button" value="Go" onclick="encode()">
<script>
var input = document.getElementById('in');
var output = document.getElementById('out');
function encode() {
var inputData = parseInt(input.value, 10);
var request = new XMLHttpRequest();
request.open('GET', '/currency', true);
request.onreadystatechange = function () {
if (request.readyState === 4) {
if (request.status === 200) {
var response = JSON.parse(request.responseText);
output.value = response.rate * inputData;
}
}
};
request.send(null);
}
</script>
</body>
</html>