• Resolved Fallbrook

    (@fallbrook)


    Hello,

    I’ve been trying to get a calculated field to return a value based on the resulting value of another field. The code seems to work, but it’s ignoring the second statement and I’m lost as to why. Here is my setup:

    I have a variable (fieldname82) that checks the value of two user entered textfields (a width and length field). The variable (fieldname82) checks the two user entered values and checks to see if one field is larger than the other – if the width field is larger, then it returns a value of ‘610W’ otherwise if the length field is larger, it returns ‘610L’

    Next, I have a second variable (fieldname28) that checks whether the value of fieldname82 is ‘610W’, or ‘914W’ or ‘1118W’ and if it is, it returns one value, otherwise if the value of fieldname82 is ‘610L’, or ‘914L’ or ‘1118L’ then it returns something else. Here is the code:

    (function(){
    if(fieldname82 == '610L' || '914L' || '1118L') return fieldname29+100;
    else if(fieldname82 == '610W' || '914W' || '1118W') return fieldname30+100;
    })();

    The code works however it does not check the second line. It only just returns the result of the first line. Any help you can provide as to why would be very much appreciated!

    • This topic was modified 9 years, 4 months ago by Fallbrook.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello,

    In javascript, if you want check if the variable A is equal to B or C, the correct syntax is:

    if( A == B || A == C)

    So, your equation should be edited as follows:

    (function(){
    if(fieldname82 == '610L' || fieldname82 == '914L' || fieldname82 == '1118L') return fieldname29+100;
    else if(fieldname82 == '610W' || fieldname82 == '914W' || fieldname82 == '1118W') return fieldname30+100;
    })();

    Another solution would be the use of the operation “IN” implemented by the plugin (http://cff.dwbooster.com/documentation#conditions-module), where the equation’s code would be:

    (function(){
    if(IN(fieldname82,['610L','914L','1118L'])) return fieldname29+100;
    else if(IN(fieldname82,['610W','914W','1118W'])) return fieldname30+100;
    })();

    Best regards.

    Thread Starter Fallbrook

    (@fallbrook)

    Thank you so much for that clarification!

    I tried the code you supplied and for some reason the form was still not picking up on the second line. When executing – it’s performing the task of the first if statement fine. So I decided to remove the alpha characters “W” and “L” and instead went with “610” and “611” and that worked…

    I love the simplicity of your IN operation so I went with that but changed the equation to remove the characters as above and that is working exactly as needed now.

    Do you know by any chance the reason that alpha-numeric configurations wouldn’t work? If not its no worry, just curious. I am very glad it’s working now and can’t thank you enough for the support you provide – amazing plugin!

    Plugin Author codepeople

    (@codepeople)

    Hello,

    The plugin tries to extract the numbers for use them in mathematical operations, however to use the characters, please, modifies the equation as follows:

    (function(){
    var tmp = fieldname82, value = jQuery('[id*="fieldname'+'82_"]').val();
    
    if(IN(value,['610L','914L','1118L'])) return fieldname29+100;
    else if(IN(value,['610W','914W','1118W'])) return fieldname30+100;
    })();

    The “tmp” variable is not used in the equation, but receives the value of the fieldname82 to let the plugin know that this equation should evaluated each time varies the value of the fieldname82 field.

    Best regards.

    Thread Starter Fallbrook

    (@fallbrook)

    Got it, thank you very much – I will definitely keep that for future use!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Conditional statement not working’ is closed to new replies.