locked
Expanding textbox when typing is not submitting data when i hit enter keyboard RRS feed

  • Question

  • User-2074858223 posted

    This code helps to expand textbox while typing but when i hit the keyboard enter it doesnt submit, the enter keyboard does not work

    <script type="text/javascript">
        $(function () {
            $("[id*=txtcommentpost], [id*=txtcommentpost2]").on("keypress", function (e) {
                if (e.which != 13) {
                    var textarea = $(this)[0];
                    textarea.oninput = function () {
                        textarea.style.height = "";
                        textarea.style.height = Math.min(textarea.scrollHeight, 300) + "px";
                    };
                }
                else {
                    e.preventDefault();
                    return false;
                }
            });
        });
    </script>

    Wednesday, January 24, 2018 4:41 PM

Answers

  • User475983607 posted

    Of course, the code is purposefully written to cancel the default behavior when enter (13) is pressed.

    Try

                else {
                    document.forms[0].submit(); 
                }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 24, 2018 4:48 PM