The CreatorCon Call for Content is officially open! Get started here.

How to change the background colors of a choice list?

Naveen Kumar J
Tera Expert

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.

5 REPLIES 5

Kalai,


I need to clear all the choice list first and then i need to add the colors as the choice list.



Capture222.PNG



Thanks,


Naveen


This is a example from HTML that I had used previously.. Makes use of css to do logic.



<html>


<head>


<style>


.redText {


      background-color:#F00;


}


.greenText {


      background-color:#0F0;


}


.blueText {


      background-color:#00F;


}


</style>


<body>


<select


      onchange="this.className=this.options[this.selectedIndex].className"


      class="greenText">


        <option class="greenText" value="green" >Green</option>


      <option class="redText"     value="red" >Red</option>


      <option class="blueText" value="blue" >Blue</option>


</select>


</body>



</html>


Naveen Kumar J
Tera Expert

This has been fixed with 2 onload client script and 1 onchnage client script. I will share the script soon. Thank you.