7 Replies Latest reply: Jan 31, 2013 5:18 AM by Martin1 RSS

    Change text colour in an item dynamically

    Martin1
      Hi,

      has somebody an idea how to change after page load dynamically the colour of the text in a text item accordingly to its value?

      Many thanks in advance.
      Best regards,
      Martin
        • 1. Re: Change text colour in an item dynamically
          fac586
          Martin1 wrote:

          has somebody an idea how to change after page load dynamically the colour of the text in a text item accordingly to its value?
          Use a Dynamic Action.

          There's insufficient information in the question to permit a more specific response.
          • 2. Re: Change text colour in an item dynamically
            Mahmoud_Rabie
            Dear Martin,

            jQuery can do it and more.

            Take a look on this
            http://apex.oracle.com/pls/apex/f?p=53647:5
            test/test

            And try to change the value of text box in the region Test Change Text Color
            write Project and press enter ---> the foreground color of the text item will be changed to red
            write anything other and press enter, it will be changed to blue

            The steps
            1) Create Text Item called P5_CHANGEMYCOLOR on region Test Change Text Color
            2) Edit the page and go to the section called Execute when Page Loads under JavaScript and write the following jQuery
            // Added By: Mahmoud Rabie (for changing color of text box based on some special values)
            if(apex.jQuery("#P5_CHANGEMYCOLOR").val() == 'Project'){
                apex.jQuery("#P5_CHANGEMYCOLOR").css("color","red");
            }else{
                apex.jQuery("#P5_CHANGEMYCOLOR").css("color","blue");
            }
            and if you want to see the code of page 5 you can write ralab in workspace with test/test

            Please, if this solves your question, mark it as Correct. Otherwise, as helpful

            Regards
            Mahmoud
            • 3. Re: Change text colour in an item dynamically
              Martin1
              Hi Mahmoud,

              thanks a lot for you reply. That's exactly what i need :-)
              What wolud you do, if the logic which decides the colour is implemented in a PL/SQL function? The input parameter of the function is the value of the appropriate item and the return value is the colour to be displayed.

              Best Regards,
              Martin
              • 4. Re: Change text colour in an item dynamically
                Mahmoud_Rabie
                Hi Martin
                thanks a lot for you reply. That's exactly what i need
                You have marked the question as answered without marking my post as Correct :)

                Regards
                Mahmoud
                • 5. Re: Change text colour in an item dynamically
                  Martin1
                  Hi Mahmoud,

                  sorry - i answered it now as correct :-)

                  Regards,
                  Martin
                  • 6. Re: Change text colour in an item dynamically
                    Mahmoud_Rabie
                    What wolud you do, if the logic which decides the colour is implemented in a PL/SQL function? The input parameter of the function is the value of the appropriate item and the return value is the colour to be displayed.
                    Attach your PL/SQL function to a hidden item let's say P5_COLOROFTEXTFIELD. So, the code will be reduced to (no need for if statement as its logic is implemented in the function)
                        apex.jQuery("#P5_CHANGEMYCOLOR").css("color","#P5_COLOROFTEXTFIELD");
                    I hope that helps.
                    • 7. Re: Change text colour in an item dynamically
                      Martin1
                      Hi Mahmoud,

                      that's it - thanks a lot.

                      Best Regards,
                      Martin