The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Chat2

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #174768

    I followed the tutorial on Chat2 and I can’t send the message. I press enter and it just adds another line to the text box. What is going on and what can I do to fix it?

    Chat2 Tutorial


    Unless we can see your code, we can’t help


    Do you have a live code example of what you’ve tried to implement?

    Ilan Firsov

    Without seeing the code we can only guess, but I think I know what your problem is.
    As far as I can tell <input /> tags by default submits the form when you press the enter key while <textarea /> does not.
    If you don’t need multiple lines you can just change the <textarea /> to <input /> and everything should be fine
    You can force <textarea /> to submit the form with Javascript:

          <textarea id="multiline"></textarea>
     $('#multiline').on('keypress', function(e) {
          if(e.which == 13) {

    And if you want to have multiline support with let’s say CTRL+Enter, just add this to the keypress callback function:

       if(e.ctrlKey && e.which == 10) { //when ctrl is pressed enter input code is 10 instead of 13
            $(this).append("\n"); // \n = line break

    Here is a quick Pen

    • I’m using jQuery here, but it should be fairly easy in vanilla JS as well
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.