Copy link to clipboard
Copied
var aNumFields = ["FieldA", "FieldB", "FieldC", "FieldD"];
function Min("aNumFields")
{
// n = number of fields that have a numerical value > 0
var i = 0;
for ( var i = 0; i<aNumFields.length; i++) {
var v = this.getField(aNumFields).value;
if ( v != ) {
n++;
min = v;
}
}
}
event.value = minValue;
I have changed this script around so many times I have probably made it impossible to correct, any assistance you can give would be greatly appreciated.
Use this code as the custom calculation script of the field:
function Min(aFields) {
var min = Infinity;
for (var i = 0; i<aFields.length; i++) {
var v = Number(this.getField(aFields).value);
if (v!=0 && v<min) min = v;
}
return (min==Infinity) ? "" : min;
}
var aFields = ["FieldA", "FieldB", "FieldC", "FieldD"];
event.value = Min(aFields);
Copy link to clipboard
Copied
Yeah, that code is a mess... I can fix it for you but I need to know what should it return if all the fields are empty (or zero)?
Copy link to clipboard
Copied
The Text box should stay blank if all the fields are zeros.
Copy link to clipboard
Copied
Use this code as the custom calculation script of the field:
function Min(aFields) {
var min = Infinity;
for (var i = 0; i<aFields.length; i++) {
var v = Number(this.getField(aFields).value);
if (v!=0 && v<min) min = v;
}
return (min==Infinity) ? "" : min;
}
var aFields = ["FieldA", "FieldB", "FieldC", "FieldD"];
event.value = Min(aFields);
Copy link to clipboard
Copied
Thank you I saved it and it worked like a charm.
Copy link to clipboard
Copied
Thank you so very much.
I would have never thought to put the var fields and value at
the end.
I must have changed it 100 times, I think it is back to school
for me. Using Java once in a blue moon I sure did forget a lot.
Thank you,
Copy link to clipboard
Copied
The location of it doesn't matter, actually. Could be before or after the function definition. The main issue was the code inside the function.
And if you want to learn it the first thing to realize is it's JavaScript, not Java. The names are similar, but the languages are quite different.