-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cgpa calculator.html
227 lines (205 loc) · 9.78 KB
/
cgpa calculator.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<!--
Note: This code is intended for use in WordPress.
Check this url for how it look in wordpress site- https://roytechub.com/vels-university-cgpa-calculator/
Explanation:-
1. Styling: The CSS styles are adapted for WordPress usage but can be further customized through WordPress themes or inline styles.
2. Media Query: The media query ensures responsiveness on phones by adjusting the layout and styling for screens up to 480px width.
3. Form Inputs: Inputs are formatted to have a consistent width and padding for better usability on smaller screens.
4. JavaScript: The JavaScript functions remain unchanged and can be added to your WordPress theme's script file or in a custom JavaScript file.
5. Functionality: The 'addSubject()' and 'deleteSubject()' functions allow dynamic addition and removal of subject input fields.
6. Result Display: The calculated CGPA is displayed dynamically in the 'result' div upon form submission.
-->
<head>
<title>CGPA Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
}
form {
max-width: 40.625rem; /* 650px converted to rem */
margin: 0 auto;
text-align: center;
}
.subjectInput {
display: flex;
justify-content: space-between;
align-items: left;
margin-bottom: 0.625rem; /* 10px converted to rem */
}
.subjectInput label {
flex: 1;
margin-left: 0.9375rem; /* 15px converted to rem */
margin-right: 0.625rem; /* 10px converted to rem */
margin-bottom: 0.625rem; /* 10px converted to rem */
text-align: left;
}
.subjectInput text{
flex-basis: 20%;
}
.subjectInput textarea {
width: calc(50% - 0.3125rem); /* 5px converted to rem */
height: 1.875rem; /* 30px converted to rem */
padding: 0.625rem; /* 10px converted to rem */
box-sizing: border-box;
margin-right: 0.3125rem; /* 5px converted to rem */
margin-bottom: 0.3125rem; /* 5px converted to rem */
resize: none; /* Disable resizing */
}
.subjectInput input {
flex: 2;
padding: 0.5rem; /* 8px converted to rem */
box-sizing: border-box;
}
input[type="button"] {
width: 49%;
background-color: #008CBA;
color: white;
padding: 0.625rem; /* 10px converted to rem */
margin-top: 0.625rem; /* 10px converted to rem */
border: none;
border-radius: 0.25rem; /* 4px converted to rem */
cursor: pointer;
}
input[type="button"]:hover {
background-color: #005f6b;
}
input[type="submit"] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 0.625rem; /* 10px converted to rem */
margin-top: 0.9375rem; /* 15px converted to rem */
border: none;
border-radius: 0.25rem; /* 4px converted to rem */
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #45a049;
}
.deleteSubject {
flex: 0 0 auto; /* Adjust the width */
margin-left: 0.625rem; /* 10px converted to rem */
background-color: #ff0000;
color: white;
border: none;
border-radius: 0.25rem; /* 4px converted to rem */
cursor: pointer;
}
.deleteSubject:hover {
background-color: #dd0000;
}
#result {
margin-top: 1.25rem; /* 20px converted to rem */
text-align: center;
}
@media only screen and (max-width: 480px) {
form {
max-width: 100%;
}
.subjectInput {
flex-wrap: wrap;
}
.subjectInput label {
flex: 100%;
margin-bottom: 0.3125rem; /* 5px converted to rem */
}
.subjectInput input,
.subjectInput textarea {
flex: 100%;
width: 100%;
margin: 0;
}
input[type="button"],
input[type="submit"] {
width: 100%;
}
}
</style>
</head>
<body>
<h2 style="text-align: center;">Calculate Your CGPA</h2>
<form id="gradeForm">
<div id="subjectInputs">
<div class="subjectInput">
<label for="subjectName"><b>Subject Name:-</b></label>
<label for="gradePoints">Grade Points:</label>
<input type="number" class="gradePoints" min="0" max="10" step="0.01" required>
<label for="credits">Credits:</label>
<input type="number" class="credits" min="0" required>
<button type="button" class="deleteSubject" onclick="deleteSubject(this)">Delete</button>
</div>
<div class="subjectInput">
<label for="subjectName"><b>Subject Name:-</b></label>
<label for="gradePoints">Grade Points:</label><br/>
<input type="number" class="gradePoints" min="0" max="10" step="0.01" required>
<label for="credits">Credits:</label>
<input type="number" class="credits" min="0" required>
<button type="button" class="deleteSubject" onclick="deleteSubject(this)">Delete</button>
</div>
<div class="subjectInput">
<label for="subjectName"><b>Subject Name:-</b></label>
<label for="gradePoints">Grade Points:</label>
<input type="number" class="gradePoints" min="0" max="10" step="0.01" required>
<label for="credits">Credits:</label>
<input type="number" class="credits" min="0" required>
<button type="button" class="deleteSubject" onclick="deleteSubject(this)">Delete</button>
</div>
<div class="subjectInput">
<label for="subjectName"><b>Subject Name:-</b></label>
<label for="gradePoints">Grade Points:</label>
<input type="number" class="gradePoints" min="0" max="10" step="0.01" required>
<label for="credits">Credits:</label>
<input type="number" class="credits" min="0" required>
<button type="button" class="deleteSubject" onclick="deleteSubject(this)">Delete</button>
</div>
<div class="subjectInput">
<label for="subjectName"><b>Subject Name:-</b></label>
<label for="gradePoints">Grade Points:</label>
<input type="number" class="gradePoints" min="0" max="10" step="0.01" required>
<label for="credits">Credits:</label>
<input type="number" class="credits" min="0" required>
<button type="button" class="deleteSubject" onclick="deleteSubject(this)">Delete</button>
</div>
</div>
<input type="button" value="Add Subject" onclick="addSubject()">
<input type="submit" value="Calculate CGPA">
</form>
<div id="result"></div>
<script>
function addSubject() {
const subjectInputs = document.getElementById('subjectInputs');
const newSubjectInput = document.createElement('div');
newSubjectInput.classList.add('subjectInput');
newSubjectInput.innerHTML = `
<label for="subjectName"><b>Subject Name:-</b></label>
<label for="gradePoints">Grade Points:</label>
<input type="number" class="gradePoints" min="0" max="10" step="0.01" required>
<label for="credits">Credits:</label>
<input type="number" class="credits" min="0" required>
<button type="button" class="deleteSubject" onclick="deleteSubject(this)">Delete</button>
`;
subjectInputs.appendChild(newSubjectInput);
}
function deleteSubject(button) {
const subjectInput = button.parentNode;
subjectInput.parentNode.removeChild(subjectInput);
}
document.getElementById('gradeForm').addEventListener('submit', function(event) {
event.preventDefault();
let totalCredits = 0;
let totalGradePoints = 0;
document.querySelectorAll('.subjectInput').forEach(subjectInput => {
const gradePoints = parseFloat(subjectInput.querySelector('.gradePoints').value);
const credits = parseInt(subjectInput.querySelector('.credits').value);
totalCredits += credits;
totalGradePoints += gradePoints * credits;
});
const cgpa = totalGradePoints / totalCredits;
const resultDiv = document.getElementById('result');
resultDiv.innerHTML = `
<h3>CGPA:</h3>
<p>${cgpa.toFixed(2)}</p>
`;
});
</script>
</body>