0

I'm making a file in HTML to be run in Edge (just on my computer), and I want to have a string of text be input into an existing .txt file. I'm very new to scripting, and can't get any php's fwrite() or JS' writeFile() to work in Edge. After searching and testing for a few hours, any help you could offer would be awesome!

This is an example I got off another Stack page, but it simply won't run when not commented out.

Thanks!

<!DOCTYPE html>
<html>
<head>
</head>
<script language="Javascript" >

/*function WriteToFile(passForm) { 

    set fso = CreateObject("Scripting.FileSystemObject");  
    set s   = fso.CreateTextFile("filename.txt", True); 
 
    var firstName = document.getElementById('FirstName'); 
    var lastName  = document.getElementById('lastName'); 
 
    s.writeline("First Name :" + FirstName); 
    s.writeline("Last Name :" + lastName); 
 
    s.writeline("-----------------------------"); 
    s.Close(); 
 } */

function tester(){
    alert("This part works");}



</script>

<body>

<button onclick="tester();">Alert Test</button>

<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"> 
</form> 

</body>
</html>
MMax5
  • 1
  • 2
    Client-side JS does not have access to the file system. – Louys Patrice Bessette Jul 18 '22 at 19:18
  • [That answer](https://stackoverflow.com/questions/52266359/the-simplest-way-to-write-files-locally-on-windows-by-client-js) would be your best option, but will trigger a file download... Won't write in an existing file. – Louys Patrice Bessette Jul 18 '22 at 19:23
  • (The example code you found containing `fso.CreateTextFile` is not meant to run in web browsers; it appears to be part of [Visual Basic](https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/createtextfile-method) for Microsoft applications.) – Daniel Beck Jul 18 '22 at 19:27

0 Answers0