jQuery <input> detect the enter key press in a text input field

Description

jQuery <input> detect the enter key press in a text input field

View in separate window

<!DOCTYPE html>
<html lang="en">
<head>
<title>Detect If Enter Key is Pressed in a Text Input Field with jQuery</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
    $(document).on("keypress", "input", function(e){
        if(e.which == 13){//from   ww  w  .  j  a va  2 s  .  co m
            var inputVal = $(this).val();
            document.getElementById("demo").innerHTML = "You've entered: " + inputVal;
        }
    });
</script>
</head>
<body>
    
    <p id="demo"></p>
        
    
    <input type="text">
</body>
</html>



PreviousNext

Related