• Resolved Damn!

    (@greedymind)


    Hello,

    I have a scenario where, when the total percentage is 100 the text should be green in color and when the total percentage is above 100 the text should be red and when the total percentage is below 100 the text should be orange. I have tried including 3 “html content” with 3 separate colors for each condition but that approach looks messy. So I just need to know if it possible to change the color of the div element from calculated field for each condition.

    code i have in html content:
    <div id="result" style="color:#FF0000; text-align:left; font-weight:600; font-size:15px;"></div>

    code i have in a calculated field:

    (function(){
    if(fieldname22 > 100)
    {
    	jQuery('#result').html('Total Percentage: '+fieldname22+'% (red)');
    }
    else if (fieldname22 < 100)
    {
    	jQuery('#result').html('Total Percentage: '+fieldname22+'% (orange)');
    }
    else if (fieldname22 == 100)
    {
    	jQuery('#result').html('Total Percentage: '+fieldname22+'% (green)');
    }
    })()

    Thanks in advance.

    • This topic was modified 7 years, 3 months ago by Damn!.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello,

    The correct code would be:

    (function(){
    var color = 'black',
    e = jQuery('#result');
    
    if(fieldname22 > 100) color = 'red';
    if(fieldname22 == 100) color = 'green';
    if(fieldname22 < 100) color = 'orange';
    
    e.css('color',color).html('Total Percentage: '+fieldname22+'%');
    })()

    I’m sorry but the support service does not include the implementation of the forms and formulas of users, if you need additional help to implement your project, I can offer you a custom coding service from my personal website:

    http://cff.dwbooster.com/customization

    Best regards.

    Thread Starter Damn!

    (@greedymind)

    works like a charm. thank you codepeople. 🙂

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘changing text color’ is closed to new replies.