I am using onkeyup function in a textbox to make a button click but when I click on enter first on TextBox cursor moving to next line and then onkeyup function is taking place. For perfection in my project I need quick onkeyup function where cursor should not go down and function should take place. Just like StackOverflow’s comment TextBox.
I am using following code:
<asp:TextBox ID="inputmess" runat="server" TextMode="MultiLine" Height="70px" Width="495px" onkeyup="if (event.keyCode == 13) document.getElementById('sendmess').click()" />
Use
keydowninstead ofkeyupandreturn false;.Another alternative:
A demo: http://jsfiddle.net/usmanhalalit/jCsY6/