-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathform.js
More file actions
executable file
·29 lines (28 loc) · 920 Bytes
/
form.js
File metadata and controls
executable file
·29 lines (28 loc) · 920 Bytes
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
/**
* Return an object of parameter values
*
* @param elements Elements as extracted using document.querySelectorAll('form')[0]
* @return ObjectOfInputs
*/
var formDataExtractor = elements => [].reduce.call(elements, (objectOfInputs, element) => {
// If it is a number, but in string form, convert it to a number
if (!isNaN(element.value)) {
objectOfInputs[element.name] = parseFloat(element.value);
} else {
objectOfInputs[element.name] = element.value;
}
return objectOfInputs;
}, {});
/**
* Read inputs from the form and enter them into an object.
*
* @params None.
* @return An object containing all the form inputs.
*/
function readInputs() {
// Form elements
var form = document.querySelectorAll('form')[0];
var objectOfInputs = formDataExtractor(form);
objectOfInputs.t0 = 0;
return objectOfInputs;
}