NotToBrag
NotToBrag

Reputation: 665

Create a text file with JavaScript

I'm trying to create a text file using javascript (online) with the following code:

   <html>
<head>
<script>
 function WriteToFile(passForm) {

    var fso = CreateObject("Scripting.FileSystemObject");  
    var s = fso.CreateTextFile("profile/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> 
</body>

However, I receive the error:

Uncaught SyntaxError: Unexpected identifier 

with the set fso line.

I hope someone can help me here

Upvotes: 0

Views: 1227

Answers (1)

Zaenille
Zaenille

Reputation: 1384

What you're looking for is var, not set, wherever you got that.

var initializes a variable within the scope where it is initialized. In that case, if you use :

var fso = CreateObject("Scripting.FileSystemObject");

then you're making an fso variable accessible inside the WriteToFile function.

Upvotes: 1

Related Questions