title: How to call the onclick function after pressing Enter
body: <p>I am making a chat web application, to send a message, there's an <code>input type="text"</code> and an <code>input type="button"</code>, using a function in JavaScript, I managed to work it out by adding <code>onclick="sendMessage()"</code> as an attribute for the <code>input button</code>, but I need to click on it, but I want it to work like any chat messengers or apps, the client writes something down and hits ENTER key, this could work if I used a <code>&lt;form onsubmit="sendMessage()"&gt;</code> and <code>input type="submit"</code> but then the page will refresh, How can I do this?</p>