-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
61 lines (58 loc) · 1.61 KB
/
index.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link href="css/main.css" rel="stylesheet" />
</head>
<body>
<div class="container">
<h1>Unit converter</h1>
<div class="unit in">
<input id="input" />
<select name="input-measure">
<option value="mm">Миллиметр</option>
<option value="cm">Сантиметр</option>
<option value="m">Метр</option>
<option value="mile">Миля</option>
<option value="foot">Фут</option>
</select>
</div>
<div class="equal">
=
</div>
<div class="unit">
<input id="output" disabled/>
<select name="output-measure">
<option value="mm">Миллиметр</option>
<option value="cm">Сантиметр</option>
<option value="m">Метр</option>
<option value="mile">Миля</option>
<option value="foot">Фут</option>
</select>
</div>
</div>
</body>
<script src="js/convert-functions.js"></script>
<script>
let input = document.getElementById('input');
let output = document.getElementById('output');
let selInput = document.querySelector('select[name=input-measure');
let selOutput = document.querySelector('select[name=output-measure');
input.addEventListener('input', (e) => {
convert(e.target.value);
});
selInput.addEventListener('change', (e) => {
convert(input.value);
});
selOutput.addEventListener('change', (e) => {
convert(input.value);
});
function convert(val) {
let inpM = selInput.value;
let outM = selOutput.value;
let res = toM[inpM](val);
res = fromM[outM](res);
output.value = res;
}
</script>
</html>