Skip to main content
Participant
April 14, 2023
Question

Calculating with exponents in a fillable form

  • April 14, 2023
  • 4 replies
  • 2594 views

I have a form that I'm trying to auto calculate an equation in. The equation is L=Q/(Cw X H^1.5). I can't get the exponent in the denominator to work correctly. I gave up trying to get it to work in simplified field notation and started trying Custom Calculation Script. Unfortunately I know nothing about Java. I'm experienced with SAS and R, so I'm not completely new to code, I've just never learned Java. The script I currently have is as below. Where is my mistake, please? Thank you! Note: Current values of fields Q and H are 0.887 and 0.5, respectively. 

 

event.value=((this.getField("Q"))/(this.getField("H") **= 1.5)); 

This topic has been closed for replies.

4 replies

Bernd Alheit
Community Expert
Community Expert
April 15, 2023

Is this following?

L=Q/(Cw x H^1.5)

Participant
April 17, 2023

That's the equation I'm attempting to code.

Nesa Nurani
Community Expert
Community Expert
April 15, 2023

To calculate exponent, use Math.pow(), something like this:

var q = Number(this.getField("Q").valueAsString);
var h = Number(this.getField("H").valueAsString);

if(h)
event.value = q/Math.pow(h,1.5);
else
event.value = "";

Participant
April 17, 2023

Thank you! This did it! Ending code was:

 

var q = Number(this.getField("Q").valueAsString);
var h = Number(this.getField("H").valueAsString);
event.value = q/(3*Math.pow(h,1.5));

try67
Community Expert
Community Expert
April 14, 2023

The first thing to know when writing code is what language you're using, so you could search for it correctly online. In this case it's JavaScript, not Java. If you google "javascript math exponents" you'll immediately find the right way of doing it.

Participant
April 17, 2023

I apologize, I'm not a programmer. I honestly don't know the difference between Java and JavaScript. That said, I'm assuming the two are related and that JavaScript is some sort of subsidiary to Java, which is why I used the term Java in a general sense. Kind of like how you refer to a Chevy instead of a Chevy Cobalt or Chevy Blazer. I apologize for offending your sensibilities in this regard. Just so you know, I had done extensive online searching using the term JavaScript and none of the solutions worked, which is why I'm here.

Legend
April 17, 2023

"I apologize, I'm not a programmer. I honestly don't know the difference between Java and JavaScript."

No need to apologise, it's a very common error. But it's important that we correct it, so you can get the info you need to program. (Because, yes, you are a programmer if you are doing this!)

"That said, I'm assuming the two are related and that JavaScript is some sort of subsidiary to Java, which is why I used the term Java in a general sense. "

No. They have a shared history, but they are different, and mixing them up will just mean you constantly find advice that will cause you endless wasted time... like mixing up an alligator and an alligator handbag - you really want to know which one of these is in the back of your Chevy...

Participant
April 14, 2023

Latest iteration: 

 

event.value=((this.getField("Q").value)/((this.getField("H").value) ** 1.5))