I am trying to set up a HTML select box where the user can enter morning, noon and night. I also want this to editable if the user returns to the site.
If for example the user were to choose night, and then returned to the page a day later, when they open the page, the page would first fetch the users data and store it in a variable called “when”
When the select box loads i would like to to to determine the value of “when” (morning, noon or night) and set the select box to that value.
Any guidance would be greatly appreciated.
var when = Noon;
// I TRIED BOTH OF THE FOLLOWING:
document.getElementById(‘times’).options[“Noon”].selected = true;
document.getElementById(‘times’).options.selected = true;
<form name="myForm" id="myForm">
****<select name=“times” id=“times”>
***** * *<option value="1">Morning</option>
***** * *<option value="2">Noon</option>
* * * ****<option value="3">Night</option>