Results 1 to 4 of 4

Thread: simple chat

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

    Question simple chat

    Hello,
    I have a code for simple chat
    3 windows
    -one for nickname
    -second for message/comments
    -third where all messages/comments appears from all visitors.

    no password, no sign up needed.

    Question: onclick "send"button I need message appears in 3rd window and 2nd clear.

    Pleease,help.
    Thank you.

    <html>
    <head>
    <title>ASP Chat Box</title>
    <META http-equiv="refresh" content="">
    </head>

    <body>
    <&#37;
    if request.Form("func") = "Send" then

    nickName = trim(request.Form("nickName"))

    chatBox = trim(request.Form("chatBox"))

    session("nickName") = nickName

    Set objFlSys = Server.CreateObject("Scripting.FileSystemObject")
    chatFile = Server.MapPath ("chatlog.txt")
    Set objStreamOutput= objFlSys.OpenTextFile (chatFile, 1, TRUE)
    ipaddr=Request.ServerVariables("REMOTE_ADDR") & " : "
    objStreamOutput.Write "<b>" & nickName & "</b>:"
    objStreamOutput.WriteLine chatBox & "<BR>" & vbnewline
    Set objStreamOutput = Nothing

    end if

    Set objFlSys = Server.CreateObject("Scripting.FileSystemObject")
    chatFile = Server.MapPath ("chatlog.txt")
    Set objStreamInput = objFlSys.OpenTextFile (chatFile, 1, False, False)
    Response.Write objStreamInput.ReadALL & "<br/>"
    Set objStreamInput=Nothing

    %>

    <form action="" method="post" >
    <strong>Nickname :</strong>
    <p>
    <input name="nickName" value=""nickName")" size="18"/><br/>
    </p>
    <p>
    <strong>Message : </strong>
    <br/>
    <textarea cols="14" rows="11" name="chatBox"></textarea>
    <input type="submit" name="func" value="Send"/>
    <textarea cols="25" rows="11" name="chatBox0"></textarea></p>
    </form>

    </body>

    </html>

  2. #2
    Join Date
    Jan 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Hope this helps!!

    This is just off the top of my head so pardon me for any silly mistakes


    You will have to add an onclick evebt to the submit button i.e.
    onClick = "Display()".

    The display() will have the code

    var msg = document.getelementbytagName("chatbox").value;
    document.getelementbytagName("chatbox0").value = msg;
    document.getelementbytagName("chatbox").value = "";
    document.formname.action = "filename.asp"
    document.formname.submit

    From your code I see that the form is never submitted. Request.form will not work in that case. So use the above code and see if you can get it to work with yours.

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

    Default

    Thank you for advise,
    I did something wrong.
    Where should I correct?




    <html>
    <head>
    <title>ASP Chat Box</title>
    <META http-equiv="refresh" content="">


    </head>
    <body>

    <&#37;
    if request.Form("func") = "Send" then

    nickName = trim(request.Form("nickName"))

    chatBox = trim(request.Form("chatBox"))

    session("nickName") = nickName

    Set objFlSys = Server.CreateObject("Scripting.FileSystemObject")
    chatFile = Server.MapPath ("chatlog.txt")
    Set objStreamOutput= objFlSys.OpenTextFile (chatFile, 1, TRUE)
    ipaddr=Request.ServerVariables("REMOTE_ADDR") & " : "
    objStreamOutput.Write "<b>" & nickName & "</b>:"
    objStreamOutput.WriteLine chatBox & "<BR>" & vbnewline
    Set objStreamOutput = Nothing

    end if

    Set objFlSys = Server.CreateObject("Scripting.FileSystemObject")
    chatFile = Server.MapPath ("chatlog.txt")
    Set objStreamInput = objFlSys.OpenTextFile (chatFile, 1, False, False)
    Response.Write objStreamInput.ReadALL & "<br/>"
    Set objStreamInput=Nothing

    var msg = document.getelementbytagName("chatbox").value;
    document.getelementbytagName("chatbox0").value = msg;
    document.getelementbytagName("chatbox").value = "";
    document.formname.action = "filename.asp"
    document.formname.submit



    %>

    <form action="" method="post" >
    <strong>Nickname :</strong>
    <p>
    <input name="nickName" value=""nickName")" size="18"/><br/>
    </p>
    <p><strong>Message : </strong>
    <br/><textarea cols="14" rows="11" name="chatBox"></textarea>
    <input type="submit" name="func" value="Send" onclick="Display()"/>
    <textarea cols="25" rows="11" name="chatBox0"></textarea></p>
    </form>

    </body>

    </html>

  4. #4
    Join Date
    Jan 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    **var msg = document.getelementbytagName("chatbox").value;
    document.getelementbytagName("chatbox0").value = msg;
    document.getelementbytagName("chatbox").value = "";
    document.formname.action = "filename.asp"
    document.formname.submit**

    This has to be in the function which you are invoking on the 'onclick' event of the button. Since the event is Javascript hence the function has to be enclose within the <script type="Javascript"> tag.


    ***document.formname.action = "filename.asp"
    document.formname.submit***

    the formname is the actual name of the form on your page. I see that you have not given a name to the form.

    **filename.asp**

    And this is the name of the asp page that you are submitting. Since the same page will reload, hence this will be the name of the page that has the code.

    I do not know much about creating a chat application, hence this code will just do what you asked for initially.

    Hope this helps!!

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
  •