I'm working on an option form. I want each option to have a different color on the scroll down and once an option is selected I want to save it, and display the selection and color.
What I want to be able to do is save the form, come back to the page and see the option I previously selected while displaying the color. In the picture above 2020 shows an example of the options. What I want after I save the form is for my selection to appear (like in 2021) with the selection color(in this case 2021 is medium/yellow). What can I do so that the selected box option takes the color of the option in the scroll down? How can I save this so that the option remains selected the next time I visit the page?
HTML
<form action="" method="post">
{% csrf_token %}
{% for year in years %}
<select name="rating" id="{{year.id}}">
<script src="{% static 'SCS/scripts/script.js' %}"/></script>
<option>Choose From List</option>
<option class=green value="green">High</option>
<option class=yellow value="yellow">Medium</option>
<option class=orange value="orange">Low</option>
<option class=gray value="gray">N/A</option>
</select>
<input type="hidden" name="year" value={{year.fy_year}}>
{% endfor %}
<input id=save_cap type="submit" value="Save">
</form>
CSS
.green{
background-color: green;
}
.yellow{
background-color: yellow;
}
.orange{
background-color: orangered;
}
.gray{
background-color: gray;
}