0

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

3
  • Where did you get the code from? It seems to be written for IE and VBScript. Commented Sep 13, 2014 at 13:45
  • From here: dreamincode.net/forums/topic/… Commented Sep 13, 2014 at 13:58
  • Actually @fgb you are right, this is solely for use with IE, I gues s I'll have to look for another alternative. Commented Sep 13, 2014 at 14:05

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Mark, that got rid of the errors, I thought set was some type of specific thing js had for file creating but I guess not, anyway, the code still doesn't work!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.