<!DOCTYPE html>




<html lang="en">




<head>




<meta charset="utf-8">




<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());




    });




});




</script>




</head>




<body>




    <p><input type="text" placeholder="Type something..." id="myInput"></p>




    <div id="result"></div>
























    <h1>Detect ENTER key with jQuery</h1>




        <label>TextBox Area: </label>




        <input id="someTextBox" type="text" size="40" />




        <script type="text/javascript">




            //Bind keypress event to textbox




            $('#someTextBox').keypress(function(event){




                var keycode = (event.keyCode ? event.keyCode : event.which);




                if(keycode == '13'){




                    alert('You pressed a "enter" key in textbox');  




                }




                //Stop the event from propogation to other handlers




                //If this line will be removed, then keypress event handler attached 




                //at document level will also be triggered




                event.stopPropagation();




            });




             




            //Bind keypress event to document




            $(document).keypress(function(event){




                var keycode = (event.keyCode ? event.keyCode : event.which);




                if(keycode == '13'){




                    alert('You pressed a "enter" key in somewhere');    




                }




            });




        </script>




</body>




</html>




