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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *