Categories
JavaScript Answers

How to change selected option by value in a HTML select element using JavaScript?

Spread the love

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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.