Sometimes, we want to change selected option by value in a HTML select element using JavaScript.
In this article, we’ll look at how to change selected option by value in a HTML select element using JavaScript.
How to change selected option by value in a HTML select element using JavaScript?
To change selected option by value in a HTML select element using JavaScript, we can set its value
property.
For instance, we write
document.getElementById("sel").value = "bike";
to select the drop down with getElementById
.
Then we set its value
property to the value of the option element with the value we’re looking for.
Conclusion
To change selected option by value in a HTML select element using JavaScript, we can set its value
property.