i have a form like this :
<form method="post">
<input type="text" name="msg" id="chat_in" >
<input type="button" name="bt" id="bt">
</form>
i want to send data when user pressing enter or clicking on button
it's work when user click on button , but it doesn't work when user pressing enter on chat_in
here is my javascript :
$(document).ready(function () {
function SendData() {
$.ajax({
url: "save.php",
type: "post",
data: "msg="+$('#chat_in').val(),
dataType: 'json',
success: function(){
alert("Sent");
},
error:function(){
alert("failure");
}
});
}
$('#chat_in').keypress(function(e) {
if(e.which == 13) {
alert('You pressed enter!');
SendData();
}
});
$('#bt').click(function() {
SendData();
});
});
how can i solve this problem ?