nitiphone2021 Posted February 24, 2021 Share Posted February 24, 2021 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 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? Quote Link to comment https://forums.phpfreaks.com/topic/312207-add-button-click-when-enter-key-on-input-text/ Share on other sites More sharing options...
maxxd Posted February 25, 2021 Share Posted February 25, 2021 You shouldn't have multiple elements with the same ID. In your case, your input is being duplicated and the id is "chat_message_{to_user_id}", so when there are multiple instances of the input element they're all assigned the same id - in this case, "chant_message_13". Quote Link to comment https://forums.phpfreaks.com/topic/312207-add-button-click-when-enter-key-on-input-text/#findComment-1584769 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.