Page 2 of 2 FirstFirst 12
Results 11 to 11 of 11

Thread: simple chat

  1. #11
    Join Date
    Dec 2006
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question i've got a script but...

    - 2 text boxs
    -one for the username
    -one for the user message
    -verytime a user sends a message it clears both the username
    and message box

    I am getting a ot of ERRORS


    <html>
    <head>

    <applet>
    codebase="http://client4.addonchat.com/current/"
    code="Client.class" archive="scclient_en.zip"
    alt="AddonChat Java Chat Software"
    width=600 height=400 MAYSCRIPT>
    <param name="room" value="176356">
    </applet>

    <script type="text/javascript">
    /* Writing Ajax Requests */
    var http_request=false;
    var http_request2=false;
    var intUpdate;function ajax_request(url){http_request=false;
    if(window.XMLHttpRequest){http_request=new XMLHttpRequest();
    if(http_request.overrideMimeType){http_request.overrideMimeType('text/xml');}}
    else if(window.ActiveXObject){

    try{http_request=new ActiveXObject("Msxml2.XMLHTTP");}
    catch(e){try{http_request=new ActiveXObject("Microsoft.XMLHTTP");}
    catch(e){}}}
    if(!http_request){alert();return false;}
    http_request.onreadystatechange=alertContents;http_request.open('GET',url,true);http_request.send(null);}

    function alertContents(){
    if(http_request.readyState==4){
    if(http_request.status==200){rec_response(http_request.responseText);}else{}}}

    /* Reading Ajax Requests */
    function ajax_request2(url){http_request2=false;
    if(window.XMLHttpRequest){http_request2=new XMLHttpRequest();
    if(http_request2.overrideMimeType){http_request2.overrideMimeType('text/xml');}}
    else if(window.ActiveXObject){try{http_request2=new ActiveXObject("Msxml2.XMLHTTP");}
    catch(e){try{http_request2=new ActiveXObject("Microsoft.XMLHTTP");}
    catch(e){}}}
    if(!http_request2){alert();
    return false;}
    http_request2.onreadystatechange=alertContents2;http_request2.open('GET',url,true);http_request2.send(null);}

    function alertContents2(){
    if(http_request2.readyState==4){
    if(http_request2.status==200){rec_chatcontent(http_request2.responseText);}
    else{}}}

    /* Chat Stuff */
    waittime=2000;
    intUpdate=window.setTimeout("read_cont()", waittime);
    chatwindow.value = "connecting...";

    function display_msg(msg1) {
    /* Fill Textarea with the Content */
    document.getElementById("chatdiv").innerHTML=msg1 ;
    }
    function write_msg(msg1) {
    ajax_request("w.php?m=" + escape(msg1));
    }

    function submit_msg() {
    /* Send My Message */
    write_msg(chatname.value + chatnms.value + chatmsg.value);
    chatname.value="";
    chatnms.value=": ";
    chatmsg.value="";
    }

    function rec_response(str1) {
    /* Response From w.php */
    }

    function rec_chatcontent(cont1) {
    if (cont1 != "") {
    out1 = "";
    /* Display Last Message First */
    while (cont1.indexOf("\n") > -1) {
    out1 = cont1.substr(0, cont1.indexOf("\n")) + "\n" + out1;
    cont1 = cont1.substr(cont1.indexOf("\n") + 1);
    }
    out1 = unescape(out1);
    if (chatwindow.value != out1) { display_msg(out1); }
    intUpdate=window.setTimeout("read_cont()", waittime);
    }
    }

    function read_cont() {
    /* Prevent Buffering by using ?x=timeinms */
    zeit = new Date();
    ms = (zeit.getHours() * 24 * 60 * 1000) + (zeit.getMinutes() * 60 * 1000) + (zeit.getSeconds() * 1000) + zeit.getMilliseconds();
    ajax_request2("chat.txt?x=" + ms);
    }
    function keyup(arg1) { if (arg1 == 13) { submit_msg(); } }
    </script>
    </head>



    <body>

    <textarea id="chatwindow" rows="10" cols="80" style="border:1px solid #aaaaaa; padding:4px;" readonly></textarea><br>
    <input id="chatname" type="text" size="20" style="border:1px solid #aaaaaa;">
    <input id="chatnms" type="hidden" value=": ">
    <input id="chatmsg" type="text" size="20" style="border:1px solid #aaaaaa;"
    onkeyup="keyup(event.keyCode);">
    <input type="button" value="ok" onclick="submit_msg()" style="cursorointer;border:1px solid gray;">
    </body>
    </html>

    Last edited by lelu; 01-15-2007 at 07:08 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •