As a new learner of JavaScript, I have managed to figure out how to retrieve values from my select drop down. However, one issue I am currently facing is displaying a default value when a user first visits the page, which then changes based on the selection made from the drop down menu. Right now, no value is displayed until an option is chosen from the drop down. Despite trying to search for a simple guide on how to achieve this, I have not been successful. Below is the code I am working with:
function val() {
d = document.getElementById("select_year").value;
document.getElementById("demo").innerHTML = d;
}
<select onchange="val()" id="select_year">
<option selected value="2017">2017</option>
<option value="2016">2016</option>
<option value="2015">2015</option>
</select>
<p id="demo"></p>