• Resolved mack1990

    (@mack1990)


    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 7 replies - 1 through 7 (of 7 total)
  • Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter mack1990

    (@mack1990)

    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.

    Plugin Author codepeople

    (@codepeople)

    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.

    Thread Starter mack1990

    (@mack1990)

    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 ;/

    Plugin Author codepeople

    (@codepeople)

    Hello @mack1990

    You can contact me directly through my website: Click Here

    Best regards.

    Thread Starter mack1990

    (@mack1990)

    Hi,

    i am about to write to functions but I cannot see my mistakes:

    (function(){

    if(fieldname203 == “A” && fieldname90 = “A”)
    return 1.08;
    }
    if(fieldname204 == “A” && fieldname90 = “B”)
    return 1.08;
    }
    if(fieldname203 == “B” && fieldname90 = “A”)
    return 1.23;
    }
    if(fieldname204 == “B” && fieldname90 = “B”)
    return 1.23;
    }
    if(fieldname90 == “C”) return 1.23;
    }
    })()

    and one harder, but similar with hide/show
    fieldname99 “A” show fieldname 100, 101, 102; “B” 103, 104, 105
    and I want fieldname200 show “A” 100 and 103, “B” 101, 104 and “C” 102 and 105
    you know.. finally I want to show someone pool 100 if he choose 99 “A” and 200 “A”; 104 if 99 “B” and 200 “B”. ect.
    then count

    `(function(){
    if(fieldname204 == “A” && fieldname206 == “A”)
    return (fieldname3*12)/fieldname5;

    if(fieldname204 == “A” && fieldname206 == “B”)
    return (fieldname207*6)/fieldname8;

    if(fieldname204 == “A” && fieldname206 == “C”)
    return ((fieldname208*1)/fieldname5);

    if(fieldname204 == “B” && fieldname206 == “A”)
    return (fieldname209*12*fieldname5);

    if(fieldname204 == “B” && fieldname206 == “B”)
    return (fieldname210*6*fieldname5);

    if(fieldname204 == “B’ && fieldname206 == “C”)
    return (fieldname211*1*fieldname5);
    })();

    Plugin Author codepeople

    (@codepeople)

    Hello @mack1990

    Your equation has some parser errors. It includes many close parentheses (}) without the corresponding open parentheses ({). In addition, the operator for equality is the double symbol == because the symbol = is used for assignment.

    The correct equation would be:

    (function(){
    if(fieldname203 == "A" && fieldname90 == "A") return 1.08;
    if(fieldname204 == "A" && fieldname90 == "B") return 1.08;
    if(fieldname203 == "B" && fieldname90 == "A") return 1.23;
    if(fieldname204 == "B" && fieldname90 == "B") return 1.23;
    if(fieldname90 == "C") return 1.23;
    })()

    If you want to display fields based on the choices ticked by users, you should define dependencies in the radio buttons or checkbox fields. More information about dependencies by reading the following blog post:

    https://cff.dwbooster.com/blog/2020/03/01/dependencies

    Best regards.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Dropbox with functions’ is closed to new replies.