I'm making simple chatroom, I have textarea in index.php where user can input his/her message. I used link to pass the values in ajax instead of button. In my situation, I usually, click the "send" link in order to pass the values. But how can I solve this when user hit enter his/her message and automatically, display to the div?
**
Index.php
**
<form name="form1" onsubmit="submitAjaxQuery(event)" >
<textarea name="msg"></textarea><br/>
<a href="#" onclick="submitChat()"> Send </a>
</form>
function submitChat(){
if( form1.msg.value ==''){
alert("All fiels are mandatory");
return;
}
form1.uname.readonly=true;
form1.uname.style.border='none';
var uname= form1.uname.value;
var msg = form1.msg.value;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4 && xmlhttp.status ==200)
{
document.getElementById('chatlogs').innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open('GET','insert.php?uname='+uname+'&msg='+msg,true);
xmlhttp.send();
}