Click here to Skip to main content
15,303,151 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
JavaScript
<pre><script>
        $(document).ready(function(){
            $("#send-btn").on("click", function(){
				$value = $("#data").val();
                $msg = '<div class="user-inbox inbox"><div class="icon"></div><div class="msg-header"><p>'+ $value +'</p></div></div>';
                $(".form").append($msg);
                $("#data").val('');
                
                // start ajax code
                $.ajax({
                    url: 'message.php',
                    type: 'POST',
                    data: 'text='+$value,
                    success: function(result){
                        $replay = '<div class="bot-inbox inbox"><div class="icon">^__i class="fas fa-robot fa-lg"></div><div class="msg-header"><p>'+ result +'</p></div></div>';
                        
                        
						$(".form").append($replay);
                        // when chat goes down the scroll bar automatically comes to the bottom
                        $(".form").scrollTop($(".form")[0].scrollHeight);
                    }
                });
            });
        });
    </script>


What I have tried:

<pre lang="Javascript">$("#send-btn").("click", function(){
Posted
Updated 11-Dec-21 9:23am

1 solution

Use the eventcode and either keyup or keydown
e.g. event.keyCode === 13
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900