• Resolved johnhorning-1

    (@johnhorning-1)


    Love your plugin, and sorry if you’ve answered this before, but I’m having trouble displaying different text depending upon a calculated value.

    In the plugin description, I see this: “you can make the “Instruct. Text” fields dependent from the calculated value, that way you can change the text shown to the user depending of the number shown in the calculated price”.

    I tried this, but don’t see a way to make the text dependent on a value calculated for a previous field. Can you help?

Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter johnhorning-1

    (@johnhorning-1)

    To clarify a bit more, I want to change the text under “Your net income” depending on whether net income is positive or negative at the bottom of the forms on this page: https://localzi.com/the-smart-alternative-to-groupon/

    • This reply was modified 5 years, 2 months ago by johnhorning-1.
    Plugin Author codepeople

    (@codepeople)

    Hello @johnhorning-1

    I’ll try to describe the process with a hypothetical example.

    Assuming there is a field in the form whose default label is: “Text A”, but you want change the text of this label to: “Text B” if the result of the equation: fieldname1+fieldname2 is lesser than 0

    – First, assign a custom class name to the field whose label you want to vary, for example: custom-field

    Note: the class names are assigned to the fields through their attributes: “Add CSS Layout Keywords”

    – Second, edit the equation as follows:

    
    (function(){
    var result = fieldname1+fieldname2,
        label = IF(result < 0, 'Text B', 'Text A');
    jQuery('.custom-field label').html(label);
    return result;
    })()
    

    and that’s all.

    The text is determined based on the equation’s result, and it is entered into the label of the field whose class is: custom-field, and finally, the equation returns the calculated result.

    Best regards.

    Thread Starter johnhorning-1

    (@johnhorning-1)

    Thank you for that quick response, but where do I enter the equation? I don’t see a place for an equation in the Instruct. Text field.

    Plugin Author codepeople

    (@codepeople)

    Hello @johnhorning-1

    The equations are entered into the settings of calculated fields and not into the “Instruct. Text” fields. Please, read again my previous entry, I’m controlling the text of the “Instruct. Text” field from the equation associated to the calculated field.

    Best regards.

    Thread Starter johnhorning-1

    (@johnhorning-1)

    Thanks! Got it working.
    If I might impose, I have one more question. Is there a way to change the color of the text or background of the label of the text field (at the bottom) depending on the results of the calculated field?
    https://localzi.com/the-smart-alternative-to-groupon/

    • This reply was modified 5 years, 2 months ago by johnhorning-1.
    Plugin Author codepeople

    (@codepeople)

    Hello @johnhorning-1

    Yes of course, in the same way you call:

    
    jQuery('.custom-field label').html(label);
    

    You can include:

    
    jQuery('.custom-field label').css('color', 'red');
    

    Best regards.

    • This reply was modified 5 years, 2 months ago by codepeople.
    Thread Starter johnhorning-1

    (@johnhorning-1)

    Thanks, but what I meant was change the color depending on the results of the calculated field? In other words, if the value is greater than 0, color is green; if less than 0, color is red.

    Plugin Author codepeople

    (@codepeople)

    Hello @johnhorning-1

    In the same way I’m selecting the label in my code, and assigning it to a variable, you can do the same with a color code:

    
    (function(){
    var result = fieldname1+fieldname2,
        label = IF(result < 0, 'Text B', 'Text A'),
        color = IF(result < 0, 'red', 'blue');
    jQuery('.custom-field label').html(label);
    jQuery('.custom-field label').css('color', color);
    return result;
    })()
    

    Best regards.

    Thread Starter johnhorning-1

    (@johnhorning-1)

    Thanks!

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to display different text depending upon a calculated value’ is closed to new replies.