Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript keypress multiple records problems

I would like to ask why it will have multiple response? How can i enter the input field with just one response?

Expectation : Input the data in input field and press the enter , it will execute the actions.

$("#textInput").keypress(function (e) {

  console.log("123");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>

<input type='text' id='textInput'/>
like image 340
Lamp Chan Avatar asked May 17 '26 18:05

Lamp Chan


1 Answers

You have syntax error in you code. closing should be }); instead of )};

$("#textInput").keypress(function (e) {
     if(e.which == 13) {
        alert('You pressed enter!');
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="textInput">
like image 157
Dinesh undefined Avatar answered May 19 '26 08:05

Dinesh undefined