-
Notifications
You must be signed in to change notification settings - Fork 0
/
index-03.html
126 lines (114 loc) · 2.46 KB
/
index-03.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Salary Calculator</title>
<style>
body{
margin-left: 50px;
}
.field{
margin-bottom: 10px;
}
label{
display: block;
}
#tdSalary{
color : red;
font-size: 20pt;
}
</style>
<script src="jquery-3.3.1.min.js"></script>
<script>
String.prototype.toInt = function() {
return parseInt(this, 10);
};
//Model
function SalaryCalculator(){
//state
this.basic = 0;
this.hra = 0;
this.da = 0;
this.tax = 0;
this.salary = 0;
}
//behavior
SalaryCalculator.prototype.calculate = function() {
var gross = this.basic + this.hra + this.da;
var net = gross * ((100-this.tax)/100);
this.salary = net;
};
//View
$(function(){
window.calculator = new SalaryCalculator();
$('#txtBasic').change(function(){
calculator.basic = $('#txtBasic').val().toInt();
});
$('#txtHra').change(function(){
calculator.hra = $('#txtHra').val().toInt();
});
$('#txtDa').change(function(){
calculator.da = $('#txtDa').val().toInt();
});
$('#rangeTax').change(function(){
calculator.tax = $('#rangeTax').val().toInt();
});
$('#btnCalculate').click(function(){
calculator.calculate();
$('#tdSalary').html(calculator.salary);
$('#tdBasic').html(calculator.basic);
$('#tdHra').html(calculator.hra);
$('#tdDa').html(calculator.da);
$('#tdTax').html(calculator.tax);
});
});
</script>
</head>
<body>
<h1>Salary Calculator</h1>
<hr>
<section>
<div class="field">
<label for="">Basic :</label>
<input type="number" id="txtBasic">
</div>
<div class="field">
<label for="">HRA :</label>
<input type="number" id="txtHra">
</div>
<div class="field">
<label for="">DA :</label>
<input type="number" id="txtDa">
</div>
<div class="field">
<label for="">Tax :</label>
<input type="range" id="rangeTax" min="0" max="30" value="0">
</div>
<div class="field">
<input type="button" value="Calculate" id="btnCalculate">
</div>
<div class="field">
<table>
<thead>
<tr>
<th>Basic</th>
<th>HRA</th>
<th>DA</th>
<th>Tax</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td id="tdBasic">[Basic]</td>
<td id="tdHra">[Hra]</td>
<td id="tdDa">[Da]</td>
<td id="tdTax">[Tax]</td>
<td id="tdSalary">[Salary]</td>
</tr>
</tbody>
</table>
</div>
</section>
</body>
</html>