I have a drop down and I need to display all the colors in the drop down using Javascript.
I have coded this way. which makes the back ground colored as per the color I select from the drop down.
<select id="colorSelect" class="colorSelect" onchange="this.style.backgroundColor=this.options[this.selectedIndex].style.backgroundColor" >
<option selected value="blue" style = "background:black"></option>
<option value="red" style = "background:red"></option>
<option value="green" style = "background:green"></option>
<option value="yellow" style = "background:yellow"></option>
<option value="gray" style = "background:gray"></option>
<option value="pink" style = "background:pink"></option>
<option value="orange" style = "background:orange"></option>
<option value="aqua" style = "background:aqua"></option>
</select>
But I need something like the image below. Can you please suggest how to achieve this functionality? Selecting any color from the dropdown should retain the value.