Skip to main content
Inspiring
March 27, 2021
Answered

dynamic calculations

  • March 27, 2021
  • 2 replies
  • 7586 views

Hello!

I am making a form with the purpose of having different simple calculations depending on a dropdown field:

Depending on Dropdown make field 3 calculate the feild1* feild2

I need this calculation to be able to change when feild1 or feild2 is edited.

 

I know how to change field values depending on dropdowns but I don't know what script I would use for changing the calculation inside a certain field.

 

Any help would be greatly apreciated!

Thank you in advance.

This topic has been closed for replies.
Correct answer Nesa Nurani

Wait, so you just want to multiply field1*field2 depending on dropdown choice?

 


Try this as calculation script:

if(Number(this.getField("ID1").value) >0 && Number(this.getField("ID1").value) <= 999)
event.value = Number(this.getField("No1").value)*Number(this.getField("Price1").value);

2 replies

try67
Community Expert
Community Expert
March 27, 2021

Setting event.rc is not going to work. This only applies to user-inputted values, not automatically calculated ones.

Instead, I would do it all using a custom calculation script (not a validation one, either).

If you provide the exact specifications of how it should work we can help you out with the code to achieve it.

Flynn0101Author
Inspiring
March 27, 2021

@try67 

This is all I'm after! I think if I have this information I should be able to understand how to alter it.
Depending on Dropdown make field 3 calculate feild1 Multiplied by feild2
Thank you for your help!

try67
Community Expert
Community Expert
March 27, 2021

This is not enough. You need to provide more details, such as:

- What are the exact field names of the fields involved?

- What values of the "drop-down field" should cause Field3 to be Field1*Field2?

- What should be the value of Field3 when another value is selected under the "drop-down field"?

 

ls_rbls
Community Expert
Community Expert
March 27, 2021

Be a  little more specific.

 

What exactly is the dropdown menu providing in its list: Numbers?   Words?  Listed items with an export value?

 

How many items are in that dropdown menu and What item exactly needs to be selected from that list in order for field 3 to execute the calculating event?

 

If I understood correctly, field 3 will display the product of field1* field2 values. Correct? But if any of those two fields values are manually edited by the user, and as long as the desired list item remains selected in the dropdown menu, the value in field 3 must update when the user inputs a different value in fields1 and fields2 respectively, correct?

 

I think that you may be able to accomplish this using a custom calculation script in field 3.

 

In my example below I created a dropdwon menu named "myDropdown", and I also  added three items to that list: "item1", "item2", "item3".

 

So in my example,  when the user selects"item2" from dropdown field 3 it  automatically multiply whatever input values are in field1 and field2.

 

 

 

var f = this.getField("myDropdown").value;

  if (f != "item2" && (this.getField("field1").value !=="" || this.getField("field2").value !=="") )  {

  event.value =  "";

} else {

  event.value = this.getField("field1").value * this.getField("field2").value;

}

 

 

The script above is an example and it can be improved, but you may need to be more specific about what you're trying to accomplish.

 

Flynn0101Author
Inspiring
March 27, 2021

My goal is to be able to change the calculations in certain fields like so:

I want to be able to edit the calculation through here, is there a way javascript can do this (maybe by selecting/unselecting this option?

Flynn0101Author
Inspiring
March 27, 2021

@ls_rbls 
The reason I want it done this way is that I can still edit these fields that are being multiplied.

Thanks for your response