I'm trying to set a messaging website (school purposes).
What I want to happen is that when the user presses Enter the text in the textbox will be sent to a PHP page called InsertMessage.php
and DisplayMessages.php
and the text box to be set to "".
Instead, When I press enter the text box will only go down a line.
$(document).ready(function() {
$("#ChatText").keyup(function(e) {
//when we press enter
if (e.keycode == 13) {
var ChatText = $("#ChatText").val();
$.ajax({
type: 'POST',
url: 'InsertMessage.php',
data: {
ChatText: ChatText
},
success: function() {
$("$ChatMessages").load("DisplayMessages.php");#
("ChatText").val("");
}
});
}
});
setInterval(function() {
$("#ChatMessages").load("DisplayMessages.php");
}, 1500);
$("#ChatMessages").load("DisplayMessages.php");
});
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="ChatBig">
<div id="ChatMessages" class="scrollbar">
</div>
<textarea id="ChatText" name="ChatText" placeholder="Type Message..."></textarea>
</div>