Is it possible to set the background-color of a specific option in a choice list?

uluerje
Mega Expert

I have a choice list with red, green, yellow, and I need it to display the actual color instead of the word when the user expands the dropdown.   If I can't accomplish this through modifying the CSS, would it be possible to use a macro in place of the field?    

1 ACCEPTED SOLUTION

No problem.   Since it clears out the choice list onLoad, you have to grab the current value before it clears, then set the value back in after adding the options.   I set the background color of the field at the end of the onLoad script and also with an onChange script.   Here's part of the onLoad script...



g_form.clearOptions('u_risk_level');


  var x = document.getElementById("u_deliverable.u_risk_level");


  var option1 = document.createElement("option");


  option1.text = "Green";


  option1.name = "Green";


  option1.value = "1";


  option1.style.backgroundColor = '#32CD32';


  option1.style.color = '#32CD32';


x.add(option1);


View solution in original post

13 REPLIES 13

Bhavesh Jain1
Giga Guru

Right click on the fields, personalize styles.Create New.


In the value field, you can write: choicelist Value eg. Red


Capture.PNG


Regards,


Bhavesh


IGate-logo.png


http://www.igate.com


Personalizing the style will set the background color of the field but it won't set the background color of each individual choice within the choice list.   Below is a screenshot of what I did with an onLoad script...I wasn't able to do it by personalizing the style.  



MultiColorDropdownList.jpg


I see....thats cool.Appreciate if you could share the script so it is handy when we need it.


No problem.   Since it clears out the choice list onLoad, you have to grab the current value before it clears, then set the value back in after adding the options.   I set the background color of the field at the end of the onLoad script and also with an onChange script.   Here's part of the onLoad script...



g_form.clearOptions('u_risk_level');


  var x = document.getElementById("u_deliverable.u_risk_level");


  var option1 = document.createElement("option");


  option1.text = "Green";


  option1.name = "Green";


  option1.value = "1";


  option1.style.backgroundColor = '#32CD32';


  option1.style.color = '#32CD32';


x.add(option1);


Thank you