Is there a better solution ?

Is there a better solution ?

Hi All, 
         I have to change the back-ground color of some input fields on a screen based on some conditions.I am planning to add the widget names to database for each condition and  I will add a action in which I would like to get a list of widget names,  iterating though them to create a jquery script . I will call this function from all the places that require this functionality and will use "run javascript" action to run the script created. Is there a better solution to this problem ?

Assuming those conditions depends on user input, it seems the best way of doing it.
The alternative would be to have the background color of each input in a variable that you would need to edit. Same amount of work and not easy to maintain.
Hi ksah,

Why don't you use the extended properties to define the style of the input and set the background according to the conditions?
The traditional approach (which I am NOT in love with), is to add an extended property named "style" and have an expression setting the style. This will be treated as a "style" attribute on the HTML tag.

The issue that extended property approach have is that you are essentially repeating the logic in each input, I have more than 40 inputs on the screen so that approach really scared me off.
ksah -

Yes, I agree, it's NOT ideal. :(

Maybe the best thing is to assign them all a class (or an extra class on top of what they already have) and then just use 1 line of jQuery or JavaScript to edit the background color of that class?

the logic that determines which inputs have to have background color is complex so input 1, input 2 can have backgound color according to logic 1 . input 2, input 3, input 10 can will have backgound color according to logic 2 and so on. So what I am doing is to have a database with widget names grouped by logic and in the jquery I using id wildcard to get the client side id from widget name and it is working fine so far.
Not a good approach since you don't control the widget id. Any change that might have and you're logic is broken.

How are you storing the widgets names in database and how are you creating the jQuery script?
I am using the jquery wildcard and the generated id always have the widget name embedded. So the only thing that this solution is dependent on is the widget name. 
You may want to consider using the extended properties to add an attribute like "data-group" with a value, then use an attribute selector to specify which group you need to change the bg color for.

Thanks Justin, I will look at data-group approach to see if this is a better solution.