0

im new to coding and new to this forum. For a school project i tried to make a little website but i need to write my "textbox" value to a .txt file, i found a code on internet and i tried it but that didn't worked. Can someone help me ?

Here is the code in html :

<!DOCTYPE html>
<html lang="en-us">

<!--backgroud style-->
    <body style="background-color:white;">
<!--receive message-->  
    <a style="color:black">voici la page de l'admin</a>

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

<!--javascript-->
<script>
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(); 
 } 
</script>
  </body>
</html>
  • press F12 and look in the console. You will likely have several errors. It looks like you are trying to use VBA in JavaScript – mplungjan Mar 25 '21 at 14:17
  • You cannot write to the filesystem via javascript. You need a backend for this. Try node.js, c#, etc. – Nicolas I Mar 25 '21 at 14:18
  • 3
    @NicolasI You can create a file and suggest the user downloads it – mplungjan Mar 25 '21 at 14:20
  • That script you've found seems to try and use ActiveX. That won't work except in old versions of internet explorer. And good job it doesn't, since it's a horrendous security risk. Do what mgplungjan suggests and find out how to generate a file object and suggest the user downloads it. Either that or send the data to a server instead. – ADyson Mar 25 '21 at 15:07

0 Answers0