Copy link to clipboard
Copied
Hi, I am very rookie with Java and need a form field to check a condition then return a value, my code looks like this:
OnFocus:
event.value = this.getfield("R_15b").value;
if(event.value < 13){
Event.value = this.getfield("R_18")}
else{event.value = 0}
R_18 is a calculated field and R_15b is an input field both preceding the event however when I tab to the field it seems to pause and run the script but the field does not populate.
Please can someone assist in pointing out my error
Regards
Use this code as the custom calculation script of "A":
event.value = (Number(this.getField("B").valueAsString)<=12) ? this.getField("C").valueAsString : 0;
Copy link to clipboard
Copied
What are you trying to achieve, exactly?
Copy link to clipboard
Copied
What needs to happen is that the event field (field A) looks at a field (field B) and determines if it is less than or equal to 12, if yes, then return the value from a different field (field C), otherwise give zero.
Then there is an additional field that does the same thing but for when its greater than 12.
Copy link to clipboard
Copied
Use this code as the custom calculation script of "A":
event.value = (Number(this.getField("B").valueAsString)<=12) ? this.getField("C").valueAsString : 0;
Copy link to clipboard
Copied
Shot! worked like a charm.
Copy link to clipboard
Copied
If I need to apply the same logic but for a range (12<("B")<18), would the logic be event.value = (Number(this.getField("B").valueAsString) >=12 && <=18) ?
Copy link to clipboard
Copied
Sorry for the spam, basically I need the next field to check if field B is between 12 & 18 and if so, multiply field C by 1.5
Copy link to clipboard
Copied
In that case I would suggest to split it into individual if-conditions, like this:
var b = Number(this.getField("B").valueAsString);
var c = Number(this.getField("C").valueAsString);
if (b<=12) event.value = c;
else if (b<=18) event.value = c * 1.5;
else event.value = 0;
Copy link to clipboard
Copied
Perfect! thanks very much for your help!
Copy link to clipboard
Copied
Use
event.value = this.getfield("R_18").value
not
Event.value = this.getfield("R_18")