-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
381 lines (301 loc) · 18.5 KB
/
index.js
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
function showNumber() {
alert(addedValue);
}
function assignLength() {
var awesomeValue = document.getElementById('fromValue').value;
var cmNumber = document.getElementById("fromCENTIMETER").value;
var awesomeAssign = awesomeValue + cmNumber;
alert(awesomeAssign);
}
// Assigning function
function METERgetSelected (){
var fromRadios = document.getElementsByName('from');
var fromValue = document.getElementById('fromValue').value;
var toRadios = document.getElementsByName('to');
var toValue = document.getElementById('toValue').value;
var dpiValue = document.getElementById('dpiValue').value;
for (var fi = 0, fLength = fromRadios.length; fi < fLength; fi++)
for (var ti = 0, tLength = fromRadios.length; ti < tLength; ti++)
// METER METER METER METER METER
if (fromRadios[fi].checked && toRadios[ti].checked) {
// do whatever you want with the checked radio
if (fromRadios[fi].value == "m" && toRadios[ti].value == "m") {
var operatorValue = fromValue;
document.getElementById('toValue').value = operatorValue;
document.getElementById('formula_text').innerHTML = "these are the same units";
}
if (fromRadios[fi].value == "cm" && toRadios[ti].value == "m") {
var operatorValue = fromValue / 100;
document.getElementById('toValue').value = operatorValue.toFixed(0);
document.getElementById('formula_text').innerHTML = "divide the length value by 100";
}
if (fromRadios[fi].value == "mm" && toRadios[ti].value == "m") {
var operatorValue = fromValue / 1000;
document.getElementById('toValue').value = operatorValue;
document.getElementById('formula_text').innerHTML = "divide the length value by 1000";
}
if (fromRadios[fi].value == "in" && toRadios[ti].value == "m") {
var operatorValue = fromValue / 39.37;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "divide the length value by 39.37";
}
if (fromRadios[fi].value == "px" && toRadios[ti].value == "m") {
var operatorValue = fromValue * 0.0002645833;
document.getElementById('toValue').value = operatorValue.toFixed(5);
document.getElementById('formula_text').innerHTML = "multiply the length value by 0.000265";
}
if (fromRadios[fi].value == "p" && toRadios[ti].value == "m") {
var operatorValue = fromValue / 236;
document.getElementById('toValue').value = operatorValue.toFixed(6);
document.getElementById('formula_text').innerHTML = "for an approximate result, divide the length value by 236";
}
if (fromRadios[fi].value == "pt" && toRadios[ti].value == "m") {
var operatorValue = fromValue / 2835;
document.getElementById('toValue').value = operatorValue.toFixed(6);
document.getElementById('formula_text').innerHTML = "for an approximate result, divide the length value by 2835";
}
// METER METER METER METER METER METER METER METER
// CENTIMETER CENTIMETER CENTIMETER CENTIMETER CENTIMETER
if (fromRadios[fi].value == "m" && toRadios[ti].value == "cm") {
var operatorValue = fromValue * 100;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 100";
}
if (fromRadios[fi].value == "cm" && toRadios[ti].value == "cm") {
var operatorValue = fromValue;
document.getElementById('toValue').value = operatorValue;
document.getElementById('formula_text').innerHTML = "these are the same units";
}
if (fromRadios[fi].value == "mm" && toRadios[ti].value == "cm") {
var operatorValue = fromValue / 10;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "divide the length value by 10";
}
if (fromRadios[fi].value == "in" && toRadios[ti].value == "cm") {
var operatorValue = fromValue * 2.54;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 2.54";
}
if (fromRadios[fi].value == "px" && toRadios[ti].value == "cm" && dpiValue == 0) {
document.getElementById('formula_text').innerHTML = "a DPI value is needed for this conversion, please input a value below";
document.getElementById('toValue').value = 0;
} else if (fromRadios[fi].value == "px" && toRadios[ti].value == "cm" && dpiValue > 0) {
document.getElementById('formula_text').innerHTML = "multiply the pixel value to the quotient of 2.54 and DPI value or (pixel value * (2.54 / DPI))";
var operatorValue = fromValue * (2.54 / dpiValue);
document.getElementById('toValue').value = operatorValue.toFixed(2);
}
if (fromRadios[fi].value == "p" && toRadios[ti].value == "cm") {
var operatorValue = fromValue / 2.362;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "for an approximate result, divide the length value by 2.362";
}
if (fromRadios[fi].value == "pt" && toRadios[ti].value == "cm") {
var operatorValue = fromValue / 28.346;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "for an approximate result, divide the length value by 28.346";
}
// CENTIMETER CENTIMETER CENTIMETER CENTIMETER CENTIMETER
// MILLIMETER MILLIMETER MILLIMETER MILLIMETER MILLIMETER
if (fromRadios[fi].value == "m" && toRadios[ti].value == "mm") {
var operatorValue = fromValue * 1000;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 1000";
}
if (fromRadios[fi].value == "cm" && toRadios[ti].value == "mm") {
var operatorValue = fromValue * 10;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 10";
}
if (fromRadios[fi].value == "mm" && toRadios[ti].value == "mm") {
var operatorValue = fromValue;
document.getElementById('toValue').value = operatorValue;
document.getElementById('formula_text').innerHTML = "these are the same units";
}
if (fromRadios[fi].value == "in" && toRadios[ti].value == "mm") {
var operatorValue = fromValue * 25.4;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 25.4";
}
if (fromRadios[fi].value == "px" && toRadios[ti].value == "mm" && dpiValue == 0) {
document.getElementById('formula_text').innerHTML = "a DPI value is needed for this conversion, please input a value below";
document.getElementById('toValue').value = 0;
} else if (fromRadios[fi].value == "px" && toRadios[ti].value == "mm" && dpiValue > 0) {
var operatorValue = fromValue * (25.4 / dpiValue);
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the pixel value to the quotient of 25.4 and DPI value or (pixel value * (25.4 / DPI))";
}
if (fromRadios[fi].value == "p" && toRadios[ti].value == "mm") {
var operatorValue = fromValue * 4.233;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "for an approximate result, multiply the length value by 4.233";
}
if (fromRadios[fi].value == "pt" && toRadios[ti].value == "mm") {
var operatorValue = fromValue / 2.835;
document.getElementById('toValue').value = operatorValue.toFixed(4);
document.getElementById('formula_text').innerHTML = "for an approximate result, divide the length value by 2.835";
}
// MILLIMETER MILLIMETER MILLIMETER MILLIMETER MILLIMETER
// INCHES INCHES INCHES INCHES INCHES INCHES INCHES INCHES
if (fromRadios[fi].value == "m" && toRadios[ti].value == "in") {
var operatorValue = fromValue * 39.37;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 39.37";
}
if (fromRadios[fi].value == "cm" && toRadios[ti].value == "in") {
var operatorValue = fromValue / 2.54;
document.getElementById('toValue').value = operatorValue.toFixed(4);
document.getElementById('formula_text').innerHTML = "divide the length value by 2.54";
}
if (fromRadios[fi].value == "mm" && toRadios[ti].value == "in") {
var operatorValue = fromValue / 25.4;
document.getElementById('toValue').value = operatorValue.toFixed(4);
document.getElementById('formula_text').innerHTML = "divide the length value by 25.4";
}
if (fromRadios[fi].value == "in" && toRadios[ti].value == "in") {
var operatorValue = fromValue;
document.getElementById('toValue').value = operatorValue;
document.getElementById('formula_text').innerHTML = "these are the same units";
}
if (fromRadios[fi].value == "px" && toRadios[ti].value == "in" && dpiValue == 0) {
document.getElementById('formula_text').innerHTML = "a DPI value is needed for this conversion, please input a value below";
document.getElementById('toValue').value = 0;
} else if (fromRadios[fi].value == "px" && toRadios[ti].value == "in" && dpiValue > 0) {
var operatorValue = fromValue / dpiValue;
document.getElementById('toValue').value = operatorValue.toFixed(6);
document.getElementById('formula_text').innerHTML = "divide the pixel value to the DPI";
}
if (fromRadios[fi].value == "p" && toRadios[ti].value == "in") {
var operatorValue = fromValue / 6;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "divide the length value by 6";
}
if (fromRadios[fi].value == "pt" && toRadios[ti].value == "in") {
var operatorValue = fromValue / 72;
document.getElementById('toValue').value = operatorValue.toFixed(6);
document.getElementById('formula_text').innerHTML = "divide the length value by 72";
}
// INCHES INCHES INCHES INCHES INCHES INCHES INCHES INCHES
// PIXEL PIXEL PIXEL PIXEL PIXEL PIXEL PIXEL PIXEL PIXEL
if (fromRadios[fi].value == "m" && toRadios[ti].value == "px") {
var operatorValue = fromValue * 3779.5280352161;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 3779.53";
}
if (fromRadios[fi].value == "cm" && toRadios[ti].value == "px" && dpiValue == 0) {
document.getElementById('formula_text').innerHTML = "a DPI value is needed for this conversion, please input a value below";
document.getElementById('toValue').value = 0;
} else if (fromRadios[fi].value == "cm" && toRadios[ti].value == "px" && dpiValue > 0) {
var operatorValue = fromValue * (dpiValue/2.54);
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value to the quotient of the DPI and 2.54 or (length value * (DPI / 25.4))";
}
if (fromRadios[fi].value == "mm" && toRadios[ti].value == "px" && dpiValue == 0) {
document.getElementById('formula_text').innerHTML = "a DPI value is needed for this conversion, please input a value below";
document.getElementById('toValue').value = 0;
} else if (fromRadios[fi].value == "mm" && toRadios[ti].value == "px" && dpiValue > 0) {
var operatorValue = (fromValue * dpiValue) / 25.4;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "divide the product of the length value and DPI to 25.4 or ((length value * DPI) / 25.4)";
}
if (fromRadios[fi].value == "in" && toRadios[ti].value == "px" && dpiValue == 0) {
document.getElementById('formula_text').innerHTML = "a DPI value is needed for this conversion, please input a value below";
document.getElementById('toValue').value = 0;
} else if (fromRadios[fi].value == "in" && toRadios[ti].value == "px" && dpiValue > 0) {
var operatorValue = fromValue * dpiValue;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value to the DPI";
}
if (fromRadios[fi].value == "px" && toRadios[ti].value == "px") {
var operatorValue = fromValue;
document.getElementById('toValue').value = operatorValue;
document.getElementById('formula_text').innerHTML = "these are the same units";
}
if (fromRadios[fi].value == "p" && toRadios[ti].value == "px") {
var operatorValue = fromValue * 16.00000200315;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 16";
}
if (fromRadios[fi].value == "pt" && toRadios[ti].value == "px") {
var operatorValue = fromValue * 1.333333;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 1.33";
}
// PIXEL PIXEL PIXEL PIXEL PIXEL PIXEL PIXEL PIXEL PIXEL
// PICA PICA PICA PICA PICA PICA PICA PICA PICA PICA PICA
if (fromRadios[fi].value == "m" && toRadios[ti].value == "p") {
var operatorValue = fromValue * 236;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 236";
}
if (fromRadios[fi].value == "cm" && toRadios[ti].value == "p") {
var operatorValue = fromValue * 2.362;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 2.362";
}
if (fromRadios[fi].value == "mm" && toRadios[ti].value == "p") {
var operatorValue = fromValue / 4.233;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "divide the length value by 4.233";
}
if (fromRadios[fi].value == "in" && toRadios[ti].value == "p") {
var operatorValue = fromValue * 6;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 6";
}
if (fromRadios[fi].value == "px" && toRadios[ti].value == "p") {
var operatorValue = fromValue * 0.0625;
document.getElementById('toValue').value = operatorValue.toFixed(4);
document.getElementById('formula_text').innerHTML = "multiply the length value by 0.0625";
}
if (fromRadios[fi].value == "p" && toRadios[ti].value == "p") {
var operatorValue = fromValue;
document.getElementById('toValue').value = operatorValue;
document.getElementById('formula_text').innerHTML = "these are the same units";
}
if (fromRadios[fi].value == "pt" && toRadios[ti].value == "p") {
var operatorValue = fromValue / 12;
document.getElementById('toValue').value = operatorValue.toFixed(4);
document.getElementById('formula_text').innerHTML = "divide the length value by 12";
}
// PICA PICA PICA PICA PICA PICA PICA PICA PICA PICA PICA
// POINT POINT POINT POINT POINT POINT POINT POINT POINT POINT
if (fromRadios[fi].value == "m" && toRadios[ti].value == "pt") {
var operatorValue = fromValue * 2835;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 2835";
}
if (fromRadios[fi].value == "cm" && toRadios[ti].value == "pt") {
var operatorValue = fromValue * 28.346;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 28.346";
}
if (fromRadios[fi].value == "mm" && toRadios[ti].value == "pt") {
var operatorValue = fromValue * 2.835;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 2.835";
}
if (fromRadios[fi].value == "in" && toRadios[ti].value == "pt") {
var operatorValue = fromValue * 72;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 72";
}
if (fromRadios[fi].value == "px" && toRadios[ti].value == "pt") {
var operatorValue = fromValue * 0.75;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 0.75";
}
if (fromRadios[fi].value == "p" && toRadios[ti].value == "pt") {
var operatorValue = fromValue * 12;
document.getElementById('toValue').value = operatorValue.toFixed(2);
document.getElementById('formula_text').innerHTML = "multiply the length value by 12";
}
if (fromRadios[fi].value == "pt" && toRadios[ti].value == "pt") {
var operatorValue = fromValue;
document.getElementById('toValue').value = operatorValue;
document.getElementById('formula_text').innerHTML = "these are the same units";
}
// POINT POINT POINT POINT POINT POINT POINT POINT POINT POINT
// only one radio can be logically checked, don't check the rest
;}
}
console.log(METERgetSelected)