Get dropdown selected value in jQuery

$('selector').val() returns the selected value of a dropdown. If you want to get the selected value of a drowpdown on its change event you have to use only $(this).val()

You can also get the text of dropdown by using below code.

$(".ddlCountry option:selected").text()

CODE
<!DOCTYPE html>
<html>
<head>
  <title>jQuery With Example</title>
  <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
  <script type="text/javascript">
    $(function () {
      $('.btnClick').click(function () {
        alert('Value = ' + $('.ddlCountry').val());
        alert('Text = ' + $('.ddlCountry option:selected').text());
      });

      $('.ddlCountry').change(function () {
        alert($(this).val());
      });

    });
  </script>
</head>
<body>
  <div>
    <select class="ddlCountry">
      <option value="1">India</option>
      <option value="2">Japan</option>
      <option value="3">England</option>
    </select>
    <br /><br />
    <input type="button" class="btnClick Button" value="Click" />
  </div>
</body>
</html>
DISPLAY


1 comment :