write to file with javascript
write to file with javascript
(OP)
Hello,
I'm trying to have a user input their name on a webpage and then have the webpage store that name in a text file on the server. I have a form on a webpage where a user types their name in and then after pressing submit the name gets saved in a text file. But for some reason this does not work for me. Please help!! Here is my code.
I'm trying to have a user input their name on a webpage and then have the webpage store that name in a text file on the server. I have a form on a webpage where a user types their name in and then after pressing submit the name gets saved in a text file. But for some reason this does not work for me. Please help!! Here is my code.
CODE
<SCRIPT LANGUAGE="JavaScript">
function WriteToFile(passForm) {
set fso = CreateObject("Scripting.FileSystemObject");
set s = fso.CreateTextFile("C:\test.txt", True);
s.writeline("HI");
s.writeline("Bye");
s.writeline("-----------------------------");
s.Close();
}
</SCRIPT>
</head>
<body>
<p>To sign up for the Excel workshop please fill out the form below:
</p>
<form onSubmit="WriteToFile(this)">
Type your first name:
<input type="text" name="FirstName" size="20">
<br>Type your last name:
<input type="text" name="LastName" size="20">
<br>
<input type="submit" value="submit">
</form>
function WriteToFile(passForm) {
set fso = CreateObject("Scripting.FileSystemObject");
set s = fso.CreateTextFile("C:\test.txt", True);
s.writeline("HI");
s.writeline("Bye");
s.writeline("-----------------------------");
s.Close();
}
</SCRIPT>
</head>
<body>
<p>To sign up for the Excel workshop please fill out the form below:
</p>
<form onSubmit="WriteToFile(this)">
Type your first name:
<input type="text" name="FirstName" size="20">
<br>Type your last name:
<input type="text" name="LastName" size="20">
<br>
<input type="submit" value="submit">
</form>
RE: write to file with javascript
If you want to create the text file on the client then I think you'll have to use an ActiveX object otherwise you may run into permission problems (you may run into problems anyway as the user may deny you access) e.g.
CODE
<head>
<script language="javascript">
function WriteToFile()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.CreateTextFile("C:\\Test.txt", true);
s.WriteLine('Hello');
s.Close();
}
</script>
</head>
<body onLoad="WriteToFile()">
</body>
</html>
____________________________________________________________
Need help finding an answer?
Try the Search Facility or read FAQ222-2244 on how to get better results.
RE: write to file with javascript
I need to create a text file on client side right as ca8msm wrote (I want to write all user input in a text.log before submitting it to server - sometimes the connection to server freezes and a lot of input dissapiers without beeing registered on a server).
BUT, I get an error "[object Error]" with THE first sentence:
var fso = new ActiveXObject("Scripting.FileSystemObject");
I turned off NIS blocking, checked all Explorer properties about script....
Do I need to enable or install any ActiveX?
Any suggestions about this error? Thanks in advance
RE: write to file with javascript
1. You're using a non-ie browser (which doesn't support activex objects)
2. you're using an ie browser on an xp machine with sp2 installed and the activex object is being blocked
-kaht
How much you wanna make a bet I can throw a football over them mountains?
RE: write to file with javascript
Thanx
RE: write to file with javascript
Are you running this locally, or from a web server? You need to ensure that the settings are correct for the "zone" from which you are running this, AFAIK.
Hope this helps,
Dan
Dan's Page @ Code Couch
http://www.codecouch.com/dan/