Sagar Patil
Sagar Patil

Reputation: 42

Write data in text file

I have used below code:

var fso = new ActiveXObject("Scripting.FileSystemObject");
    var s = fso.CreateTextFile("test.txt", true);
    for(var j=1;j<9;j++)
    {
        s.WriteLine('Test'  + j);
    }
    s.Close();

Getting below error when I run above code: ReferenceError: ActiveXObject is not defined

Upvotes: 0

Views: 261

Answers (2)

Majed HORIA
Majed HORIA

Reputation: 9

try this This will work only on IE8

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

cridte @667776 @Faraona Faraona

Upvotes: 0

Harshal Yeole
Harshal Yeole

Reputation: 4983

ActiveXObject is available only on IE browser. So every other useragent will throw an error

On other browsers, you could any of this:

Upvotes: 1

Related Questions