Copy link to clipboard
Copied
Hi,
My boss is working on a forum that do math automatically, and one field will divide and multiply the results at the end.
He has no coding experience at all, and asked me, I've some knowledge in VB but no idea in Java.
So far I've tried copying some codes in custom script and I can never get any output for the field.
v1=this.getfield("Text11").value;
v2=this.getfield("text12").value;
event.value= v1/v2;
But if I write numbers like:
Event.value = 200/5+20;
I get results.
I've no idea about this, please bare with me.
We're trying to get "Text13" to get the result of dividing "Text11" by "Text12" then multiplied by 70
I know the code should be : Event.value= v1/v2*70;
But I'm just trying to figure why no math would work at all.
Sorry for the image quality, his PC doesn't have access to the internet.
I'll bring a flash drive and upload the file if need to be checked.
Thank you.
Copy link to clipboard
Copied
You are on the right track, but it's not Java it is JavaScript, and it is case-sensitive so "text12" and "Text12" are not the same, be careful to enter correct field names.
Also, before dividing check that divisor (v2) is not 0, or you will get an error.
Try something like this:
var v1 = Number(this.getField("Text11").valueAsString);
var v2 = Number(this.getField("Text12").valueAsString);
if(v2 !== 0)
event.value = v1/v2*70;
else
event.value = "";
Copy link to clipboard
Copied
It's also getField, not getfield, and event, not Event.
Copy link to clipboard
Copied
You can try this as 'Validation' script of "Text13" field:
this.getField("Check box16").checkThisBox(0,Number(event.value) > 90 ? true : false);
Copy link to clipboard
Copied
You are on the right track, but it's not Java it is JavaScript, and it is case-sensitive so "text12" and "Text12" are not the same, be careful to enter correct field names.
Also, before dividing check that divisor (v2) is not 0, or you will get an error.
Try something like this:
var v1 = Number(this.getField("Text11").valueAsString);
var v2 = Number(this.getField("Text12").valueAsString);
if(v2 !== 0)
event.value = v1/v2*70;
else
event.value = "";
Copy link to clipboard
Copied
It's also getField, not getfield, and event, not Event.
Copy link to clipboard
Copied
Sorry for the late reply and my lack of knowledge.
Thank you for clarifying and the extra tip on adding if statment.
My problem was with the letter case sensitive "getfield", I got used to be spoiled with VB autocorrecting me 🙂
Both answers were great and helpful, thank you so much to you both.
I've an extra question my boss asked me if possible to do.
When the same field results > 90, check box will be marked "True".
I don't know how to refer to the fields correctly:
If ("Text13" > 90)
"Check box16".value = True;
?
Shall I make a new post for this?
Thank you again and I apologize for troublign you with me.
Copy link to clipboard
Copied
You can try this as 'Validation' script of "Text13" field:
this.getField("Check box16").checkThisBox(0,Number(event.value) > 90 ? true : false);
Copy link to clipboard
Copied
Sorry for delay again. You know, holiday and new year 🙂
Happy holidays and new year to you all.
That did the trick Nesa! Bless you.
I can't think you enough, truely, thank you!
Stay awesome and I hope you have a delightful year.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more