I know this has been on here before, but I cannot seem to get any of the answers to work for me. This is greatly due to the fact that I do not know anything about JavaScript.
I am working on a form for my company and it has been requested that I set up one of the fields to automatically equal the division of two other fields. What I need is the simple notation or the custom calculation script to make this happen.
It needs to do the following calculation:
ACTUALPOINTS / POSSIBLESCORE = FINAL SCORE
"ACTUALPOINTS" is field 1. "POSSIBLESCORE" is field 2. "FINAL SCORE" should = field 1 divided by field 2.
Any help would be greatly appreciated!!!!
- JavaScript Dumb
Try this as the custom calculation script for the FINALSCORE field:
(function () {
// Get the field values, as numbers
var v1 = +getField("ACTUALPOINTS").value;
var v2 = +getField("POSSIBLESCORE").value;
// Set this field's value
if (v2 !== 0) {
event.value = v1 / v2;
} else {
// Set to blank if denominator evaluates to zero
event.value = "";
}
})();
Make sure the field calculation order is correct, and calculated fields should normally be set to read-only so the user is not able to interact with them.
(function () {
// Get the field values, as numbers
var v1 = +getField("ActualPoints").value;
var v2 = +getField("PossiblePoints").value;
// Set this field's value
if (v2 !== 0) {
event.value = v1 / v2*100;
} else {
// Set to blank if denominator evaluates to zero
event.value = util.printf("%.0f", v1 / v2);
}
})();
This is what I meant:
(function () {
// Get the field values, as numbers
var v1 = +getField("ACTUALPOINTS").value;
var v2 = +getField("POSSIBLESCORE").value;
// Set this field's value
if (v2 !== 0) {
event.value = util.printf("%.0f", v1 / v2);
} else {
// Set to blank if denominator evaluates to zero
event.value = "";
}
})();
North America
Europe, Middle East and Africa
Asia Pacific