• Resolved stuart981

    (@stuart981)


    I have 6 options, each are unique (Text Field), but have similar values on submit

    I need a hidden field to have a value calculated based on the option selected

    EG

    Option 1 – This is an Option – Value on submit = 5
    Option 2 – This is another Option – Value on Submit = 6
    Option 3 – This is a Third option – Value on Submit = 7
    Option 4 – This is the forth Option – Value on Submit = 5
    Option 5 – This is the Fifth Option – Value on Submit = 6
    Option 6 – This is the last option – Value on submit = 6

    If (fieldname3 ==”This is an Option” , fieldname3.val * 0.25, 0)

    Do a hidden field for all 6 options (one each) and then added them all together to get the right value

    Thanks in advance

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @stuart981

    I’m sorry, but I don’t understand totally your form’s structure, or why you need six hidden calculated fields.

    Could you send me the link to the page where the form is inserted, please?

    Best regards.

    Thread Starter stuart981

    (@stuart981)

    I need to do a if else statement as in Javascript, for example

    if (fieldname3 ==”This is an Option” ) {

    Then Do calc on Value on submit of Option

    }else if (fieldname3 ==”This is another Option” ) {

    Then Do calc on Value on submit of Option

    }else if (fieldname3 ==”This is a Third option” )

    Then Do calc on Value on submit of Option …..etc

    Plugin Author codepeople

    (@codepeople)

    Hello @stuart981

    You can implement the equation exactly in the same way you are describing it:

    
    (function(){
        if(fieldname3 == 'This is an Option'){
            return ...;
        }else if(fieldname3 =='This is another Option'){
            return ...;
        }else if(fieldname3 =='This is a Third option'){
            return ...;
        }
    })()
    

    Replacing the symbols … by the corresponding mathematical operations.

    Another alternative, using the “switch” operation:

    
    (function(){
        switch(fieldname3)
        {
          case 'This is an Option':
            return ...;
          break;
          case 'This is another Option':
            return ...;
          break;
          case 'This is a Third option':
            return ...;
          break; 
        }
    })()
    

    Best regards.

    Thread Starter stuart981

    (@stuart981)

    Brilliant, thank you for your speedy reply, will try that tomorrow and close the thread.

    Thread Starter stuart981

    (@stuart981)

    That works perfectly for the submitted value, so if i check the submitted vale then i can do the calculation, however i want to check the text value as the submit value is the same for some options. I am assuming that i have to submit the text as a string and use the statement to define the value that was previously submitted?

    • This reply was modified 6 years, 2 months ago by stuart981.
    Plugin Author codepeople

    (@codepeople)

    Hello @stuart981

    The equations are entered through the “Set Equation” attribute in the settings of calculated fields.

    A hypothetical equation would be:

    
    (function(){
        if(fieldname3 == 'This is an Option'){
            return fieldname2*3;
        }else if(fieldname3 =='This is another Option'){
            return fieldname2*5;
        }else if(fieldname3 =='This is a Third option'){
            return fieldname2*10;
        }
    })()
    

    Best regards.

    Thread Starter stuart981

    (@stuart981)

    Sorry edited my original reply just as you were answering

    That works perfectly for the submitted value, so if i check the submitted vale then i can do the calculation, however i want to check the text value as the submit value is the same for some options. I am assuming that i have to submit the text as a string and use the statement to define the value that was previously submitted?

    Plugin Author codepeople

    (@codepeople)

    Hello @stuart981

    In the settings of the DropDown, Checkbox and Radio buttons fields it is possible to configure if submit the value or text of choices selected.

    For additional questions related to the commercial features of the plugin, you should contact me through my private website: Contact Us

    Best regards.

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

The topic ‘Option Feild Text Value in IF statement’ is closed to new replies.