-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurrency_converter.html
104 lines (90 loc) · 2.72 KB
/
currency_converter.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script>
$(document).ready(
function set_result_label(){
$("#CAD").click(function(){
$("#equiv_text").text(function(){
return "Equivalent in " + $("#CAD").parent('label').text();
});
});
$("#MXN").click(function(){
$("#equiv_text").text(function(){
return "Equivalent in " + "Pesos";
});
});
$("#EUR").click(function(){
$("#equiv_text").text(function(){
return "Equivalent in " + $("#EUR").parent('label').text();
});
});
});
function page_reload(){
location.reload();
};
function calculate_result(){
var result_value = 0;
var USD_input = document.getElementById("USD_amt").value;
if ($("#CAD").is(':checked')){
var CAD_multiplier = 1.2;
result_value = USD_input * CAD_multiplier;
}
else if ($("#MXN").is(':checked')){
var MXN_multiplier = 0.9;
result_value = USD_input * MXN_multiplier;
}
else if ($("#EUR").prop("checked", true)){
var EUR_multiplier = 1.5;
result_value = USD_input * EUR_multiplier;
}
set_result_value(result_value);
};
function set_result_value(result_value){
$("#Other_amt").val(result_value);
};
function validate() {
var x = document.getElementById("USD_amt").value;
var text;
if (x == "") {
alert("USD must be filled out");
return false;
} else {
// If x is Not a Number or less than one
if (isNaN(x) || x < 1 ) {
text = "Input " + x + " not valid";
} else {
text = "Input OK";
}
$("#error_msg").text(text);
}
}
</script>
</head>
<body>
<p style="color:purple;font-size:150%"><b>Converting U. S. Dollars to other currencies</b></p>
<p style="color:purple">U. S. Dollar amount</p>
<input type="text" id="USD_amt" name="USD_amount">
<br>
<br>
<div style="color:purple;border: 1px solid purple">
<label><input type="radio" id="CAD" value="CAD_choice">Canadian Dollars</label>
<br>
<label><input type="radio" id="MXN" value="MXN_choice">Mexican Pesos</label>
<br>
<label><input type="radio" id="EUR" value="EUR_choice">Euros</label>
</div>
<br>
<p style="color:purple" id="equiv_text">Equivalent in ...</p>
<input type="text" id="Other_amt" name="Other_amount" value="0">
<br>
<br>
<button id="set_other_amount" onclick="validate()">Validate</button>
<button id="set_other_amount" onclick="page_reload()">Reset</button>
<button id="set_other_amount" onclick="calculate_result()">Calculate</button>
<button style="display:none" id="set_other_amount" onclick="set_result_value('5')">Set to 5</button>
<button style="display:none" onclick="document.getElementById('error_msg').innerHTML=Date()">The time is?</button>
<p id="error_msg"></p>
</body>
</html>