Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

write to file with javascript

Status
Not open for further replies.

saphiroth

Programmer
Dec 15, 2004
34
US
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.

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>
 
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.
Code:
<html>
<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.

 
Hello,

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
 
Either:

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?
sheepico.jpg
 
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.

Thanx
 
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



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top