javascript to change a textbox colour

Comments

2 comments

  • Avatar
    Jason Wells

    Hello,

    This is how you can implement some JavaScript code to change the background color. 

    Example script:

    function changeColors(internalName) {
        //this function changes the colors based on a value
        //using eFormHelper, we get the value of the control
        eFormHelper.getFieldValue({ fieldId: internalName }, function(r) {
            //if you only have one or 2 options, if/else works better than switch
            //switch works better when you have a lot of possibilities
            switch(r.data) {
                //change out these cases to make sense for your application
                //background-color is the property for the background of the text box
                //color is the property for the foreground of the text box a.k.a the font
                //colors may be used as rgb, hex, or keywords
                case "christmas": $("#" + internalName).css({ 'background-color': 'rgb(0, 255, 0)', 'color': 'red' }); break;
                case "halloween": $("#" + internalName).css({ 'background-color': 'orange', 'color': '#000000' }); break;
                case "valentines": $("#" + internalName).css({ 'background-color': 'pink', 'color': 'red' }); break;
                case "easter": $("#" + internalName).css({ 'background-color': 'yellow', 'color': 'blue' }); break;
                default: $("#" + internalName).css({ 'background-color': 'white', 'color': 'black' }); break;
            }
        });
    }

    Applying this code to the specific textbox in the advanced section of properties. This will indicate when the text box's value changes it will execute the JavaScript. See image below.

    And it will produce at output. For example, see image below.

    Let me know if this helps.

    Kind regards,

    Jason Wells

    0
    Comment actions Permalink
  • Avatar
    New To Agilepoint User

    Hi Jason.

     

    Thank you for the feedback.

    I'll give a try

     

    Thanks again

    0
    Comment actions Permalink

Please sign in to leave a comment.