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

Can you help clarify what u_deliverable is in the follow bit of code?




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


u_deliverable.u_risk_level is just a choice list on the form that I created using the OOTB functionality.   The field was actually created on another table so that's why the u_deliverable is there.   I set variable x to that choice list and then add the options to x.   I ended up going with a jquery dropdown instead of the one above because I couldn't get rid of the blue highlight.  


Hi Jessica,


Hi Experts,


I tried with the below script to add the colors to the choice list.



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);



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


  option2.text = "Red";


  option2.name = "Red";


  option2.value = "1";


  option2.style.backgroundColor = 'Red';


  option2.style.color = 'Red';


x.add(option2);



However once i select the color, it is showing the default white color instead of green. Please assist.




Thank you.


Hi Jessica,



could you please share complete script.




Regards,


NJ