1. Make sure the script is below all the HTML just where the Body Tag ends or Content Tag ends (if using Content Page).
2. Make use of [id*=txtboxchat1] as you are using ASP.Net TextBox.
3. Learn some ethics and cleanlines of programming. You are just Googling and pasting whatever you find should work.
You have mixed JavaScript with jQuery and in my opinion you don't have any knowledge of both.
As in following code you are accessing TextBox directly and it will raise a error since not written in window.onload or document ready.
var input = document.getElementById("txtboxchat1");
input.addEventListener("keyup", function (event) {
event.preventDefault();
if (event.keyCode === 13) {
$('[id*= btnsavechat2]').trigger('click');
}
});
4. Finally following is the script which works properly for me.
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<textarea id = "txtboxchat1" rows = "3" cols = "10"></textarea>
<input type="button" id="btnChat" value="Chat" onclick = "alert('Button clicked');"/>
<script type="text/javascript">
$("body").on("keypress", "[id*=txtboxchat1]", function (e) {
if (e.which == 13) {
e.preventDefault();
$("[id*=btnChat]").click();
}
});
</script>