Thursday, 22 June 2017

How to get the value of selected option in a select box using jQuery



<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>jQuery Get Selected Option Value hemant9807</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            $("select.country").change(function() {
                var selectedCountry = $(".country option:selected").val();
                alert("You have selected the country - " + selectedCountry);
            });
        });
    </script>
</head>

<body>
    <form>
        <label>Select Country:</label>
        <select class="country">
            <option value="china">china</option>
            <option value="india">India</option>
          
        </select>
    </form>
</body>

</html>

2 comments:

  1. Hi Hemant, I can see dropdown alone. I don't see alert SMS as you said above

    ReplyDelete
    Replies
    1. hello brother this code is properly working.

      Delete