add button click when enter key on input text

nitiphone2021

New member
Dear All,

from begin I have a Button, when user click this button, on javascript will create a input text name and button submit show on dialog of jquery like this

Code:
var modal_content = '<div id="user_dialog_' + to_user_id + '" class="user_dialog" title="' + office + '">';

        modal_content += '<div style="height:310px;  overflow-y: scroll; margin:0px; padding:0px;" class="chat_history " data-touserid="' + to_user_id + '" id="chat_history_' + to_user_id + '">';

        modal_content += '</div>';

        modal_content += '<div class="form-group">';

        modal_content += '</div><div class="form-group" align="right">';
        modal_content += '</div>';
        modal_content += '<hr style="margin:10px;padding:0">';
        modal_content += '<div class="input-group">';
        modal_content += '<input type="text" name="chat_message_' + to_user_id + '" id="chat_message_' + to_user_id + '" placeholder="ພິມຂໍ້ຄວາມຢູ່ບ່ອນນີ້" class="form-control chat_message" style="border: none;">';
        modal_content += '<div class="input-group-append">';
        modal_content += '<span class="input-group-text" style="background-color: transparent !important;border: none;padding:0"><div class="filediv"><input type="file" id="file"><label for="file-7"><strong><i class="fa fa-file fa-lg ml-1" aria-hidden="true"></i></strong></label></div><i name="send_chat" id="' + to_user_id + '"  class="fa fa-paper-plane fa-lg pl-1 mb-1 send_chat" aria-hidden="true"></i></span>';
        modal_content += '</div>';
        modal_content += '</div><span id="attachedfile"></span><script>$("#chat_message_' + to_user_id + '").keyup(function(event) {if (event.keyCode === 13) {$("#' + to_user_id + '").click();}});</script>';
      
        $('#user_model_details').html(modal_content);

so I tried to create a script as below to get enter key of input text name then make like user click on the button.

If I tried to double enter then I will get below error message

I don't know why it's not work. Do you have any idea to fix it?
 
There's no need to do this using JavaScript, much less JQuery.

Just use normal HTML and CSS to do it.
 
Back
Top