jQuery Form Input Change event

Introduction

Select any value from the dropdown select and see the result.

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Executing a Function on Change Event in jQuery</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
    $("select").change(function(){
        var selectedOption = $(this).find(":selected").val();
        document.getElementById("demo").innerHTML = 
           "You have selected - " + selectedOption;
    });/*from   www  .j a  v  a 2  s .  c  o  m*/
});
</script>
</head>
<body>
    <p id="demo"></p>
    <form>
        <label>City:</label>
        <select>
            <option>London</option>
            <option>Paris</option>
            <option>New York</option>
        </select>
    </form>
  
</body>
</html>



PreviousNext

Related