Support » Plugin: Calculated Fields Form » Dropbox with functions

• Hey,

``````Hi, I need to write a dropbox with a function.

text "a"
if fieldname1 <10, return 1000
if fieldname => 10, return 2000
text "b"
IF fieldname1 <10, return 10
IFfieldname1 => 10, return 20
text "c" = 200
text "d '= 300

and the second function.
if someone choose "a" in fieldname2, the value is 90
if he chose "b" then 30 ..``````

I tried:

``````(function(){
if(fieldname1 == 'A')
{
if(fieldname1<=10) return 20;
if(fieldname >10) return 30;

}
else
{
if(fieldname1 == 'B')
{
if(fieldname1<=10) return 20;
if(fieldname >10) return 30;

}
})()``````
Viewing 5 replies - 1 through 5 (of 5 total)
• Hello @mack1990

The fields’ names have the structure: fieldname#. For example, fieldname1, fieldname2, fieldname123, etc. But in your equation, you have forgotten the number component in some of the fields’ names: `if(fieldname >10) return 30;`

Furthermore, I’m not sure about the value of fieldname1 field because you are comparing it with a text value `if(fieldname1 == 'A')` and a number value `if(fieldname1<=10) return 20;`

Finally, keep in mind that javascript is a case-sensitive language. In your project’s description, the possible values of the fieldname2 field are “a”, “b”, “c”, and “d”, but your code compares with the values “A”, and “B”.

Assuming the texts are the values of the fieldname2 field in uppercase, and the numbers are the values of the fieldname1 field, the equation could be implemented as follows:

``````(function(){
switch(fieldname2)
{
case 'D' : return 300;
case 'C' : return 200;
case 'B' : return IF(fieldname1<10,10,20);
case 'A' : return IF(fieldname1<10,1000,2000);
}
})()``````

Or if you prefer to use the “if” conditional instructions:

``````(function(){
if(fieldname2 == 'A')
{
if(fieldname1<10) return 1000;
return 2000;
}
if(fieldname2 == 'B')
{
if(fieldname1<10) return 10;
return 20;
}
if(fieldname2 == 'C') return 200;
if(fieldname2 == 'D') return 300;
})()``````

Both equations are equivalents.

Best regards.

I use correct “value” and “text” name.

I something do wrong with this code.
I put this code in field6 ‘multiplier’
dropbox is in field90,
and then I do equivalents with this code in field8

field1 x field90 x field3

I try to use my calculator and put “a” id dropbox, he shows me “0”
then “b”, also “0” etc.

Hello @mack1990

You are talking now about different fields’ names and values. Could you indicate the link to the form to check your code in action, please?

Best regards.

yeah, sure, I can also send you screenshot from the control dashboard, but can I send it to you on mail? I do not want to show my fails in public ;/

Hello @mack1990