javascript | jquery

Set selected option by value via jQuery

This article describes how to set the selected option in a select by its value via jQuery.

Abhith Rajan
Abhith RajanAugust 19, 2017 · 2 min read · Last Updated:

In one of my projects, there is a search page which has few filters including linked selects, i.e the options displayed in a child select is dependent upon the option selected in another (parent). (like when we choose a country (parent), we have to show the states under the selected country in the child.)

After selecting both select, when we submit the search, it loads search result page with same filters above. The problem is that the child select value is not retained. Since when we assign the parent select selected value, it will trigger an ajax call and its response is bound to the child select.

To retain the filters as users selected, we had to set the selected value in the child select also. My child select is (Razor)

1@Html.DropDownList("childSelectName", items, new { @name = "someName" })

And inside my ajax call on parent select on change, after binding all the available option to the child select,

1if (selectedChildItemId) {
2 $("#childSelectName").val(selectedChildItemId);

In short,


Replace the Controls_ID with your select tag Id and value with the selected item value.

Abhith Rajan

Written by Abhith Rajan
Abhith Rajan is an aspiring software engineer with more than nine years of experience and has a proven successful track record of delivering technology-based products and services.

This page is open source. Noticed a typo? Or something unclear?
Improve this page on GitHub

Related SnippetsView All

Related ArticlesView All

Related VideosView All

Easy NPM Package Updates with Yarn Upgrade Interactive

The Async Await Episode I Promised

Related StoriesView All