javascript write to text file
snippet in javascript

javascript write to text file


// Requiring fs module in which 
// writeFile function is defined. 
const fs = require('fs') 
// Data which will write in a file. 
let data = "Learning how to write in a file."
// Write data in 'Output.txt' . 
fs.writeFile('Output.txt', data, (err) => { 
    // In case of a error throw err. 
    if (err) throw err; 

javascript write to text file


function WriteToFile(passForm) {
    set fso = CreateObject("Scripting.FileSystemObject"); 
    set s   = fso.CreateTextFile("<your Path>/filename.txt", True);
    var firstName = document.getElementById('FirstName');
    var lastName  = document.getElementById('lastName');
    s.writeline("First Name :" + FirstName);
    s.writeline("Last Name :" + lastName);

<form onSubmit="WriteToFile(this)">
<label>Type your first name:</label>
<input type="text" name="FirstName" id="firstName" size="20">
<label>Type your last name: </abel>
<input type="text" name="LastName" id="lastName" size="20">
<input type="submit" value="submit">