 <p>This solution below was tested and it works fine.</p> <p>First:</p> <p>Remove onkeydown event of digit. It should be like this:</p> <pre><code> &lt;input type="text" name="digit" id="digit" size="50" /&gt; </code></pre> <p>Remove onclick event of the button and set the id property.</p> <pre><code>&lt;button class="btn" id="btnClick" title="send" type="button" &gt; </code></pre> <p>create a input hidden in your html to store $cuser php var</p> <pre><code>&lt;input type="hidden" name="cuser" id="cuser" val="&lt;?php echo $cuser ?&gt;" /&gt; </code></pre> <p>Replace your javascript to the following:</p> <pre><code> $(document).ready(function(){ $("#digit").keydown(function(event){ if (event.keyCode == 13 &amp;&amp; event.shiftKey == 0) { alert("ok1"); filltxtarea($("#digit").val()); } }); $("#btnClick").click(function(){ filltxtarea($("#digit").val()); }); function filltxtarea(desctext) { var uchat = $("#cuser").val(); $(".chatboxcontent").append('&lt;div class=chatboxmessage&gt;&lt;span class="chatboxmessagefrom"&gt;' + uchat + ': &lt;/span&gt;&lt;span class="chatboxmessagecontent"&gt;' + desctext + '&lt;/span&gt;&lt;/div&gt;'); $('#digit').val(''); $('#digit').focus(); alert("ok2"); jQuery.ajax({ type: 'POST', url: 'chat.php', dataType: 'json', data: { "newrow": "desctext" }, success: function(response) { alert(response); } }) } }); </code></pre> <p>Any doubts please let me know.</p> <p>Hope it help.</p>