MADS HER .. (MIN FARS MAIL) ..
var GetChaturl = "getChatData.php";
var SendChaturl = "sendChatData.php";
var lastID = -1;
window.onload = initJavaScript;
function initJavaScript() {
document.forms['chatForm'].elements['chatbarText'].setAttribute('autocomplete','off');
//this non standard attribute prevents firefox' autofill function to clash
with this script
checkStatus(''); //sets the initial value and state of the input comment
checkName(); //checks the initial value of the input name
receiveChatText(); //initiates the first data query
}
function receiveChatText() {
if (httpReceiveChat.readyState == 4 || httpReceiveChat.readyState == 0)
{
httpReceiveChat.open("GET",GetChaturl + '?lastID=' + lastID +
'&rand='+Math.floor(Math.random() * 1000000), true);
httpReceiveChat.onreadystatechange = handlehHttpReceiveChat;
httpReceiveChat.send(null);
}
}
function handlehHttpReceiveChat() {
if (httpReceiveChat.readyState == 4) {
results = httpReceiveChat.responseText.split('---'); //the fields are
seperated by ---
if (results.length > 2) {
for(i=0;i < (results.length-1);i=i+4) { //goes through the result
one message at a time
insertNewContent(results[i+1],results[i+2],results[i+3]);
//inserts the new content into the page
}
lastID = results[results.length-4];
}
setTimeout('receiveChatText();',1000); //executes the next data query in
4 seconds
}
}
function insertNewContent(liName,liText,liBid) {
insertO = document.getElementById("outputList");
document.getElementById('chatoutput').innerHTML +="<b><a target='right'
href='../profil.php?id="+liBid+"'>P</a></b><span class='graa'>"+ liName +
"Siger:</span><br /><span class='hvid'>" + liText + "<br /></span><br>";
}
function sendComment() {
currentChatText =
document.forms['chatForm'].elements['chatbarText'].value;
if (currentChatText != '' & (httpSendChat.readyState == 4 ||
httpSendChat.readyState == 0)) {
currentName = document.forms['chatForm'].elements['name'].value;
param = 'n='+ currentName+'&c='+ currentChatText;
httpSendChat.open("POST", SendChaturl, true);
httpSendChat.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
httpSendChat.onreadystatechange = handlehHttpSendChat;
httpSendChat.send(param);
document.forms['chatForm'].elements['chatbarText'].value = '';
} else {
setTimeout('sendComment();',1000);
}
}
function handlehHttpSendChat() {
if (httpSendChat.readyState == 4) {
receiveChatText(); //refreshes the chat after a new comment has been
added (this makes it more responsive)
}
}
function checkStatus(focusState) {
currentChatText = document.forms['chatForm'].elements['chatbarText'];
oSubmit = document.forms['chatForm'].elements['submit'];
if (currentChatText.value != '' || focusState == 'active') {
oSubmit.disabled = false;
} else {
oSubmit.disabled = true;
}
}
function checkName() {
currentName = document.forms['chatForm'].elements['name'];
if (currentName.value == '') {
currentName.value = 'guest_'+ Math.floor(Math.random() * 10000);
}
}
function getHTTPObject() {
var xmlhttp;
/*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@else
xmlhttp = false;
@end @*/
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
xmlhttp = false;
}
}
return xmlhttp;
}
var httpReceiveChat = getHTTPObject();
var httpSendChat = getHTTPObject();
eller her:
www.2cool4you.dk/ajax.txt
Det er den nye kode vi bruger, men den opdatere ikke sig selv, da det er
GetElementByid, hvad er løsningen til dette ? :)