problem with a run function when clicked enter

Asked

Viewed 17 times

0

Well, I have the following javascript function that is included in a php query and that is executed when a keyup is given in an input as I do to 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){
  
  }
 });
 }
}

1 answer

1

The keyCode 13 is for the [enter]

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.