jQuery <select> get the value of selected option in a select box

Description

jQuery <select> get the value of selected option in a select box

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Get Selected Option Value</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
    $("select.country").change(function(){
        var selectedCountry = $(this).children("option:selected").val();
        document.getElementById("demo").innerHTML = 
              "You have selected the country - " + selectedCountry;
    });// w  w w .  j av  a2 s  .c om
});
</script>
</head>
<body>
    <p id="demo"></p>
    <form>
        <label>Select Country:</label>
        <select class="country">
            <option value="usa">United States</option>
            <option value="india">India</option>
            <option value="uk">United Kingdom</option>
        </select>
    </form>
</body>
</html>



PreviousNext

Related