3 Replies Latest reply on Aug 2, 2011 11:13 AM by George_Johnson

    Text formatting

    MediaSLML

      Hi i have a question about text formating using Javascript in acro forms.

       

      I have some code telling a field to print something, and i was wondering what code i would use to get just that particular line in red.

      The field that displays the info is used for many other things, and i just want that one phrase to print out in a different colour to stand out.

       

      This is my line of code

       

       

      else if(even.value == "Please select an option")

      {

      nOptionType = "No option selected, please return and select an option";

       

      nOptionCost = 0;

      }

       

      I would like to get the "No option selected, please return and select an option" in red, a quick google search kind lead me to believe i might have to make a different var and format it so that each time that var is printed it would be in red. I use the nOptionType multiple time and its just this one time i want it to be red. Or another choice would be to use that same var nOptionType but have it so that if a different option is printed it would print in the default black.

      I was wondering if i would be possible to write a case statement? like something like this

       

       

      switch(nOptionType)

      {

      case "No option selected, please return and select an option":

            nOptionType = nOptionType.fontcolor("red"); //would i have to use a colour code? or would "red" work?

           break;

      default:

           break;

      }

       

      An then just adding this to my other lines of code?

      Also is there a another simpler way im missing?

      Thanks

        • 1. Re: Text formatting
          George_Johnson MVP & Adobe Community Professional

          It's not clear from that code where you're setting the text to that value. I'm assuming the text is displayed in a form field, is that correct? If so, you can change the color of text in a field by specifying the textColor field property: http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.726.html

           

          Exactly how you do this depends on how your code is currently set up. It would be something like:

           

          getField("name of field").textColor = color.red;

           

          or

           

          event.target.textColor = color.red;

          • 2. Re: Text formatting
            MediaSLML Level 1

            First off, thanks for you reply, tis much appreciated.

             

            Im a bit of a newbie at this, im pretty sure that is the point where im setting the text to that value. Yes the text is displayed in a form field.

            Wouldn't that just make every value in that box end up in red?

            my full code is something like this:

             

            field script code (field name "Options")

             

            this.getField("HitchTotal").display = display.hidden;

            this.getField("HitchCostTotal").display = display.hidden;

            switch (event.value)

            {

                case "Option A1":    

                    this.getField("HitchTotal").display = display.visible;

                    this.getField("HitchCostTotal").display = display.visible;

                    break;

             

                default:

                    break;

             

            }

            if(event.value=="None")

            {

            nOptionType = "None";

            nOptionCost = 0;

            }

             

            else if(event.value =="Please select an option")

            {

            nOptionType = "No option selected, please return and select an option";

            nOptionCost= 0;

            }

            else if(event.value == "Option A1")

            {

            nOptionType = "Option A1";

            nOptionCost= 300.00;

            }

             

             

            Document JS

            var bOpened;

            var nOptionType;

            var nOptionCost;

             

            function initOptions()

            {

            var f =this.getField("Options").value;

            if(f == "None")

            {

                 nOptionType = "No Boom";

                 nOptionCost = 0;

            }

             

            else if(f == "Please select a option")

            {

                 nOptionType = "No option selected, please return and select an option";

                 nOptionCost = 0;

            }

             

            else if(f == "Option A1")

            {

            nOptionType = "Option A1";

            nOptionCost = 300.00;

            }

            bOpened = "true";

            }

            else

            {

            }

            }

            initOptions();

             

            script in the spot where the text appears (field name "OptionType")

            event.value = nOptionType //there are two fields, the other one is for nOptionCost

             

             

            i just want the "no option selected, please return and select an option" to apear in red

            I tried throwing that code in, and no success, and ideas on how i would integrate that code?

            Thanks

            • 3. Re: Text formatting
              George_Johnson MVP & Adobe Community Professional

              If you want just certain text within a field to have a different color than the other text, you will need to set up the field to allow rich text formatting and set the value of the field using the richValue property, specifying the appropriate spans. For more information, see:

               

              http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.721.html