Refactored javascript because submit message and pressing enter in the text box had the same functionality