• Resolved chadtesting

    (@chadtesting)


    Hi there,

    I’m sure this is a pretty straightforward question. There are times when I want to reference a value that a user has chosen earlier in my form, and output that value in text. I’m unsure whether this can be done in the label of a calculated field, or whether a different field type (HTML?) is needed for this,

    So for argument’s sake, let’s say a user chooses %fieldname1% which is a dropdown. In the dropdown they choose the value “arts”.

    In the final page, I have a calculated output, but need the label to reference the dropdown field’s value too.

    So it would say “Your average in %fieldname1% is <value>
    -or in text-
    “Your average in arts is 82.

    I hope that’s clear. Thank you.

    • This topic was modified 7 years, 10 months ago by chadtesting.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello,

    Assuming that the number 82 is the value of the fieldname2 field, and the dropdown field is the fieldname1, the equation would be simply:

    (function(){
    return 'Your average in'+fieldname1+' is '+fieldname2;
    })()

    and that’s all.
    Best regards.

    Thread Starter chadtesting

    (@chadtesting)

    Thanks so much! Is this output only available through a calculated field? Calculated fields tend to look awkward on the page with the border around it.

    Plugin Author codepeople

    (@codepeople)

    Hello @chadtesting,

    You can insert a “HTML Content” field in the form, with a piece of code similar to the following one as its content:

    <div id="result"></div>

    and then, display the result into the previous div tag from the formula:

    (function(){
    jQuery('#result').html('Your average in'+fieldname1+' is '+fieldname2);
    })()

    The plugin allows to extend the form’s potencial as your project needs.

    Best regards.

    Thread Starter chadtesting

    (@chadtesting)

    That is amazing. Works perfectly. You can use calculated fields to do pretty much anything. I have so much to learn.

    Hi, I’m trying to do the same thing as this, only take the text output of a calculated field directly, so I’ve created the div with id “result”, and I want to fill it with the result of fieldname16.

    I put this in the html field:

    <script>
    (function(){
    jQuery(‘#result’).html(fieldname16);
    })()
    </script>

    But it doesn’t work. In fact, it breaks the form. What am I doing wrong?

    Plugin Author codepeople

    (@codepeople)

    Hello,

    You can instantiate the fields by their names only in the equations, if you are inserting the code of your ticket in a “HTML Content” field, the correct would be:

    <script>
    jQuery(document).on('change', '[id*="fieldname16_"]', function(){
    jQuery('#result').html(jQuery(this).val());
    });
    </script>

    Best regards.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to reference field values (dropdown values) in labels’ is closed to new replies.