jQuery <input> detect change in text input box

Introduction

Bind the input event to an input text box using on() method to detect change event.

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<title>jQuery Detect Change in Input Field</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
    $("#myInput").on("input", function(){
        // Print entered value in a div box
        $("#result").text($(this).val());
    });/*from  w  w w.jav a2  s  .  c  om*/
});
</script>
</head>
<body>
    <p><input type="text" placeholder="Type something..." id="myInput"></p>
    <div id="result"></div>
</body>
</html>



PreviousNext

Related