PDA

View Full Version : simple chat



lelu
01-16-2007, 08:47 PM
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>

parijaatp
01-17-2007, 11:32 AM
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.

lelu
01-17-2007, 07:31 PM
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>

parijaatp
01-19-2007, 12:17 AM
**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!!