Dropdownlist set selected value

In this post we will see in jquery how toset dropdown list value or selected option by it's value. For that we simply need to get object of dropdown list in jquery and then we can set selected option by using val(). of dropdownlist.

jquery dropdownlist set selected value

Example: set dropdown list selected option by value [jQuery]

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <title>jQuery set dropdown list selected option by value</title>
    <script type="text/javascript">
      $(document).ready(function () {
        $("#go").click(function () {
          var inputText = $("#inputText").val();
          $("#numbers").val(inputText);
        });
      });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <label>Enter value between 1-3</label>
      <input type="text" id="inputText"/>
    <asp:DropDownList ID="numbers" runat="server">
    <asp:ListItem Text="1" Value="1"></asp:ListItem>
    <asp:ListItem Text="2" Value="2"></asp:ListItem>
    <asp:ListItem Text="3" Value="3"></asp:ListItem>
    </asp:DropDownList>
    </div>
    <input type="button" id="go" value="Go" />
    </form>
</body>
</html>

Summary: So in short we can use jquery to set dropdownlist item value like $("#numbers").val(inputText);. we can also set dropdown list selected option by using text like Set selected value by text.