Skip navigation
Fi_TW
Currently Being Moderated

Auto colour change?

Aug 17, 2012 3:24 AM

Tags: #auto #change #colour #form #100% #total #calculated

I would like to know how to make a calculated total automatically change colour when it hits 100%

 
Replies
  • Currently Being Moderated
    Aug 17, 2012 3:42 AM   in reply to Fi_TW

    Hi

     

    You should describe your question. What is 100% here? And color for what? TextField Color or Border Color, onfocus color what?

     

    Regards,

    Manjeet

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 17, 2012 4:26 AM   in reply to Fi_TW

    Hi,

     

    You want to change the text(textfield values). You have designed your form in LiveCycle Designer. Right.

     

    So, go to the last TextField and select it. Then go to the script section chose calculate event and also chose FormCalc as scripting language not the javascript. Write the below code

     

    if (this.rawValue ==100) then

    TextField1.ui.textEdit.border.fill.color.value = "86,155,189";

    endif

     

    Regards,

    Manjeet

     
    |
    Mark as:
  • George Johnson
    9,216 posts
    Aug 11, 2002
    Currently Being Moderated
    Aug 17, 2012 10:39 AM   in reply to Fi_TW

    You do not need to use LiveCycle Designer. You can do something like the following as the custom Calculate script:

     

    (function () {

     

        // Add up all of the field values

        var sum = +getField("text1").value;

        sum += +getField("text2").value;

        sum += +getField("text3").value;

        sum += +getField("text4").value;

        sum += +getField("text5").value;

        sum += +getField("text6").value;

        sum += +getField("text7").value;

        sum += +getField("text8").value;

     

        // Set this field value

        event.value = sum;

     

        // Set this field's text color

        event.target.textColor = sum == 100 ? color.red : color.black;

     

    })();

     

    Change the field names and colors to suit your needs. You probably want to explicitly round the sum to avoid things like: 0.2 + 0.1 = 0.30000000000000004, which will throw off the check for equivalence to 100 if non-integers are used for the inputs.

     

    Edit: corrected typo

     
    |
    Mark as:
  • George Johnson
    9,216 posts
    Aug 11, 2002
    Currently Being Moderated
    Aug 17, 2012 10:58 AM   in reply to Fi_TW

    It is intended to be the custom calculate script for the field. I did have to correct a typo after my initial post, so try again. You can remove the comments if you like. They are the lines that begin with //.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points