JavaScript: Setting the selected dropdown option by its index number

Long time no new entry. 🙂 Internship is keeping me very busy. In this blog entry I’ll show you how to select a drop down option by specifying its index number.

The JavaScript code:

The HTML code:

Refer to the JavaScript code. The selectionDD is the id of the <select> tag. The value 0 represents the index number of the option that we want to be selected, and will select the first option in the selection. Note that the index numbers start with 0, not 1.

Related Posts:

Posts that may be related to "JavaScript: Setting the selected dropdown option by its index number":

Catzie

A Filipino programmer with a variety of interests such as baking, singing, making up silly song/rap lyrics, K-pop, drawing, creating unique dessert flavors, obsessing about finding out how some things works, board games, anime, video games, and forgetting things that usually go in her long list of interests. Running small-time online dessert shops Cookies PH and Catzie's Cakery.

3 comments on “JavaScript: Setting the selected dropdown option by its index number

 

Leave a Reply

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