Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

write to file with javascript

write to file with javascript

write to file with javascript

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.


 function WriteToFile(passForm) {
    set fso = CreateObject("Scripting.FileSystemObject");  
    set s = fso.CreateTextFile("C:\test.txt", True);


<p>To sign up for the Excel workshop please fill out the form below:
<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">
<input type="submit" value="submit">

RE: write to file with javascript

If you want to create a text file on the server then you'll have to use a server side language (such as ASP, PHP etc).

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.


<script language="javascript">
function WriteToFile()
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.CreateTextFile("C:\\Test.txt", true);
<body onLoad="WriteToFile()">



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


How much you wanna make a bet I can throw a football over them mountains?

RE: write to file with javascript

Yes, it's XP with sp2, IE6. All options in IE about ActivX are Enabled or Prompt. Maybe some Add-on (ActiveX) must be installed additionaly. Or it must be by default - then what it's name in Add-on list or somewhere else.


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's Page @ Code Couch

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close