Skip to main content
Participant
December 22, 2024
Answered

Custom script math doesn't work in a forum

  • December 22, 2024
  • 1 reply
  • 782 views

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.

Correct answer Nesa Nurani

You can try this as 'Validation' script of "Text13" field:

this.getField("Check box16").checkThisBox(0,Number(event.value) > 90 ? true : false);

1 reply

Nesa Nurani
Community Expert
Community Expert
December 22, 2024

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 = "";

 

try67
Community Expert
Community Expert
December 22, 2024

It's also getField, not getfield, and event, not Event.