Issue
I have the following HTML code for inputting prompts to a chatbot:
<div class="input-group mb-3">
<input type="text" class="form-control" id="chat-input">
<div class="input-group-append">
<button id="button" class="btn btn-primary" >Enter</button>
</div>
</div>
And this is the Javascript code that executes upon clicking the button:
$("#button").click(function(){
.......
}
However, this only submits upon clicking the button, not upon pressing the enter button.
I have tried the following modifictions to the above Javascript code. However, none of them succeed in submitting the prompt by using the Enter button.
$("#button").keyup(function(event){
.........
}
$("#button").on('click', function(event){
...........
}
Solution
You need to listen to a keypress press event to be able to handle the other case.
Click 👇
$('#gpt-button').click(function() {
call your handler function here;
});
Enter (keypress event for listening when the entry key is hit.) 👇
$('#chat-input').keypress(function(event) {
if (event.which === 13) { // 13 is the key code for 'Enter'
call your handler function;
}
});
I hope this helps. Thanks.
Answered By - Tarik
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.