problem with a function run when clicked enter

0

Hello, I have the following javascript function which is included in a php query and that is executed when giving a keyup in an input how do I execute only when the enter key is clicked?

	function insertchat". $row311['k'] ."(){
	var dzx='". $row311['k'] ."'; 	
	var kmn=$( '#txtContent". $row311['k'] ."' ).val();
	var lk='".$_SESSION['k'] ."';
if(kmn!=''){
 $.ajax({
 type: 'POST',
 	data: {dzx: dzx, kmn:kmn, lk:lk},
  url: 'insertchat4.php',
  
	
  success: function(datas2){
	if(datas2!==''){
   $('.m". $row311['k'] ."').append(datas2);
	 
	 
	 }else{ $('.m". $row2['k'] ."').append('');}
	
  },
	error:function(datas2){
   
  },
  complete:function(datas2){
  
  }
 });
 }
}
    
asked by anonymous 30.08.2017 / 23:19

1 answer

1

The keyCode 13 is for the [enter]

$(document).on('keydown', function(event) {    
    if(event.keyCode === 13) {
        // código aqui    
    }    
});
    
30.08.2017 / 23:22