Code: Select all
onkeydown="if (event.keyCode == 13) add_content();"The source of the chat page:
Code: Select all
<script type="text/javascript">
try
{
if (window.XMLHttpRequest)
{
Ajax = new XMLHttpRequest();
}
else
{
Ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
}
catch(e)
{
alert(e);
};
function update_content()
{
try
{
Ajax.open("GET", "chat.php?_view=chat_content", true);
Ajax.send(null);
Ajax.onreadystatechange = function()
{
if (Ajax.readyState == 4 && Ajax.status == 200)
{
if ("end" == Ajax.responseText)
{
window.location="chat.php?_view=ended";
}
else if ("need rep" == Ajax.responseText)
{
document.getElementById("content").innerHTML = "Waiting for a representative...";
}
else if ("timeout" == Ajax.responseText)
{
window.location="chat.php?_view=timeout";
}
else
{
document.getElementById("content").innerHTML = Ajax.responseText;
}
}
};
}
catch(e)
{
//alert(e);
}
setTimeout("update_content()",5000);
}
function add_content()
{
try
{
Ajax.open("POST", "chat.php?_action=add", true);
var POST = "message=" + document.getElementById("message").value;
Ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
Ajax.setRequestHeader("Content-Length", POST.length);
Ajax.send(POST);
document.getElementById("message").value = "";
Ajax.onreadystatechange = function()
{
if (Ajax.readyState == 4 && Ajax.status == 200)
{
if ("need rep" == Ajax.responseText)
{
document.getElementById("content").innerHTML = "You must wait for a representative to post";
}
}
};
}
catch(e)
{
alert(e);
}
}
update_content();
</script>
<link rel="stylesheet" href="css/css.css" type="text/css" />
</head>
<body>
<div style="text-align: center;">
<p>
<table class="small-table" style="width: 500px;">
<tr>
<td>
<div id="content">
</div>
</td>
</tr>
<tr>
<td style="text-align: left;">
<input type="text" name="message" id="message" style="width: 100%;" onkeydown="if (event.keyCode == 13) add_content();"/>
</td>
<td>
<input type="submit" value="SEND" onclick="add_content();" class="submit-button"/>
<form action="chat.php" method="get" style="display: inline;">
<input type="hidden" name="_action" value="end_chat"/>
<input type="submit" value="END CHAT" class="submit-button"/>
</form>
</td>
</tr>
</table> </p>
</div>
</body>