In my Customer side chat application jsp page , I have a text area that displays the messages from the Agent side and also displays the message from the customer .
That works fine.My javaScript code is,
function sendMessage(){
message =trim( document.getElementById("message").value);
document.getElementById("message").value = "";
if(message != null && message !="null" && message !=""){
try
{
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var checkMsg = trim(xmlhttp.responseText.toString());
textarea = document.getElementById('textarea');
if(checkMsg != "null" && checkMsg != null && trim(checkMsg).length != 0) {
if(trim(textarea.value) == ""){
textarea.value = message = checkMsg;
textarea.scrollTop = textarea.scrollHeight;
}
else{
textarea.value += "\n"+checkMsg;
textarea.scrollTop = textarea.scrollHeight;
}
}
}
};
xmlhttp.open("POST", "SendMessageAction",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("charset","UTF-8");
xmlhttp.send("sessionId="+encodeURIComponent(sessionId)+"&userId="+encodeURIComponent(userId)+"&securekey="+encodeURIComponent(secureKey)+"&message="+encodeURIComponent(message)+"&sid="+Math.random());
}
catch(err)
{
alert(err.description);
}
}
}
In that I need to include the current time with the every messages appending in the text area at the right side corner of text area.
I can append the current time with messages but I need to append it in right side corner of textarea with every messages?
How can I do this.Please give some ideas or some code.
Here is a function that displays current date/time:
If you want, you can extract just the time lines for time only.
function update(){
time = new Date();
year = (time.getFullYear());
month = (time.getMonth() + 1);
date = time.getDate();
hours = time.getHours();
mins = time.getMinutes();
secs = time.getSeconds();
if(mins.length<2){mins = "0"+secs}
if(secs.length<2){secs = "0"+secs}
if(month.length<2){month = "0"+secs}
if(date.length<2){date = "0"+secs}
// Config Starts
if(hours>12){hours=hours-12}else{hours}
format = year+"-"+month+"-"+date+" @ "+hours+":"+mins+":"+secs;
document.form1.box1.value = format;
// Config Ends
}
setInterval("update()",1000);
To display the results use:
<script>
#right
{
float: right;
}
</script>
<div id="right">
<p>Current Date/Time is: <INPUT name="box1" type="text" size="20"></p>
</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.