-2

user enter's the 5digit number into the text field and without pressing any button it must be refelected on the simulator. I know how to write the data into simulator I just wanted to know how to fetch this user data as soon as he enters 5 digits without clicking any button that is, on pressing enter the data in the text field must be fetched.

Jaiprakash Soni
  • 4,100
  • 5
  • 36
  • 67

1 Answers1

0

YOU ASKED: "I just wanted to know how to fetch this user data as soon as he enters 5 digits without clicking any button that is, on pressing enter the data in the text field must be fetched."

HERE IS HOW, using the keypress event. I also limited the text input to 5 characters as well with maxlength="5".

$(document).ready(function() {
    $("input").keypress(function(e) {
        var key = e.which;
        if (key == 13) // the enter key code
        {
            if ($("input").val().length == 5) {
                //you get the value with $("input").val()
                alert($("input").val());
            }
        }
    });
});
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
Enter 5 characters: <input type="text" id="input" maxlength="5">
M H
  • 2,179
  • 25
  • 50